从JSP检索值到Javascript [英] Retrieve values from JSP to Javascript

查看:95
本文介绍了从JSP检索值到Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的JSP页面上的javascript:

Below is the javascript on my JSP page:

<SCRIPT language="JavaScript">
function checkPass(){

var pass1=request.getParameter('password');
var pass2=request.getParameter('password2');

    if (pass1==pass2){
        window.alert("YES");
    }
    else{
        window.alert("NO");
    }
    }
</SCRIPT>

下面是我的表单输入文本框:

Below is my form input text boxes:

                    <h:outputLabel value="Password:" for="password" />
 <h:inputSecret id="password" value="#{StaffController.staff.password}" 
            size="20" required="true"
            label="Password" >
            <f:validateLength minimum="8" />
        </h:inputSecret>

        <h:message for="password" style="color:red" />

                    <h:outputLabel value="Password:" for="password2" />
 <h:inputSecret id="password2" 
            size="20" required="true"
            label="Password" >
            <f:validateLength minimum="8" />
        </h:inputSecret>
 <h:message for="password2" style="color:red" />

下面是我的命令按钮,与onmousedown链接在一起,可以在单击时调用脚本:

Below is my commandbutton linked with onmousedown to call the script when clicked:

<h:commandButton action="#{StaffController.saveUser()}" onmousedown="checkPass();" value="Submit"/>

我似乎无法从用户输入表单中获取价值.

I can't seem to retrieve value from my user input form.

推荐答案

  1. JSF更改组件的ID-在浏览器中查看页面的源.它应该类似于表单ID +组件ID的组合

  1. JSF changes id of components - view source of your page in browser. It should be something like a combination of form id+component id

Submit命令在进行提交之前调用onmousedown事件,因此在checkPass中您没有请求对象

Submit command invokes onmousedown event before making submit, so in checkPass you do not have a request object

更好地编写用于检查密码的自定义验证器

Better to write a custom validator for checking password

这篇关于从JSP检索值到Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆