Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要帮助才能理解为什么提出请求。getParameter正在返回null_Javascript_Jsp - Fatal编程技术网

Javascript 需要帮助才能理解为什么提出请求。getParameter正在返回null

Javascript 需要帮助才能理解为什么提出请求。getParameter正在返回null,javascript,jsp,Javascript,Jsp,request.getParameter返回null。但是我看到这个值是由document.getElementById捕获的,而不是由request.getParameter捕获的。不知道为什么 <script type="text/javascript"> function checkExists(){ var NUSN=document.getElementById('UName').value;

request.getParameter返回null。但是我看到这个值是由document.getElementById捕获的,而不是由request.getParameter捕获的。不知道为什么

<script type="text/javascript">

           function checkExists(){

             var NUSN=document.getElementById('UName').value;
                       //  alert("helloeeee ");
                      // alert (" NUSN is : " + NUSN);
            <% 
            Connection conn = null;
            String url= "jdbc:sqlserver://localhost:1433;databaseName=Movie";
            String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            String username ="sam";
            Class.forName(driver);           
            conn=java.sql.DriverManager.getConnection(url,username,"sa");
            String NUSN1 = request.getParameter("UName");
            System.out.println("New user is : ");
            System.out.println(NUSN1);   //here the value is null- dont know why
            Statement stmt = conn.createStatement();
           ResultSet rs=stmt.executeQuery("select username from Userdetails where usename in ("+ NUSN1+")");
            while (rs.next()){
                if (rs.first()){
                    out.println("User name already taken");

                }
                else out.println("User name Valid");
            }



            %>
}
</script>

函数checkExists(){
var NUSN=document.getElementById('UName').value;
//警惕(“你好”);
//警报(“NUSN为:+NUSN”);
}
这是我的表格:只发布相关部分

    <tr> <td><label for="User Name">USER NAME:</label></td><br><br>
    <td><input type="text" name="UName" value="" size="10" id="UName" /></td>
     </tr>
用户名:


我猜您在提交表单时返回了false,这就是为什么为null! 参见我的示例:

<!DOCTYPE html>
<%
    if (request.getParameter("code") != null)   
        System.out.println(" AFTER SUBMIT code: "+request.getParameter("code"));
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Form</title>
</head>
<body>
<form method="post" onSubmit="return validateForm()">
Code:<input type="text" name="code" id="code"/>
<button type="submit">Submit</button>
</form>
<script>
function validateForm(){
    console.log(document.querySelector("#code"));

    <%
        System.out.println("CODE: "+request.getParameter("code"));
    %>
}
</script>
</body>
</html>

测试表
代码:
提交
函数validateForm(){
console.log(document.querySelector(“代码”);
}

用户名:

非常感谢您的回复。我应该说得更清楚些。我道歉。checkExists()函数是在输入框上创建的onblur事件。我写它是为了检查用户名是否唯一。我知道request.getParameter返回空值的原因。因为JSP是一种服务器端脚本语言,所以它将无法“看到”用户从字段中选择的内容,除非以某种方式将值提交到服务器进行处理,例如表单提交(我在web上找到了这种情况),并且onblur事件不会提交表单。因此为空值。