我是初学JSP,写了两个页面
页面1:输入用户名密码
- JScript code
<%@ page language="java" contentType="text/html;charset=gb2312"%><html> <body> 请输入用户名、密码: <form name="login" action="result.jsp" method="post"> 用户名: <input type="text" name="username" /> 密码: <input type="password" name="password" /> <input type="button" value="提交" onClick="check()" /> </form> <script type="text/javascript"> function check() { if (login.username.value == "" || login.parseword.value == "") { alert("不能为空!"); return; } window.print("adfadf"); login.submit(); }</script> </body></html>
页面2:如果用户名和密码相同,则显示注册成功
- JScript code
<%@ page language="java" contentType="text/html;charset=gb2312"%><html> <body> <%if(request.getParameter("username") == request.getParameter("password")){ out.print("恭喜!注册成功!"); %> <script type="text/javascript"> alter("congratulations"); </script> <% }else { %> <script type="text/javascript"> alter("sb"); </script> <% } %> </body></html>
当我什么都没有输入就提交的时候,很正常,会弹出不能为空的窗口。
但是当我有输入的时候,点击提交按钮就没有反应。
请问怎么回事??
------解决方案--------------------------------------------------------
JS语法错误了吧?你都没看看浏览器的错误信息?
window.print("adfadf"); // 这是想干啥?你有打印机么?而且这个函数应该是无参数的,这句话删掉吧。
------解决方案--------------------------------------------------------
另外:login.submit(); 这个引用方式不太安全,最好还是用设置ID属性,然后:
document.getElementById("login").submit();
------解决方案--------------------------------------------------------