日期:2014-05-18  浏览次数:20729 次

jsp代码执行的问题
<script   Language= "JavaScript ">
function   check()   {
if   (document.forms[0].item( "userID ").value   ==   " ")   {
alert( "用户不能为空! ");
return   false;
}   else   if   (document.forms[0].item( "passWord ").value   ==   " ")   {
alert( "密码不能为空! ");
return   false;
}   else   {
<%
String   strUserID   =   request.getParameter( "userID ");
String   strPassWord   =   request.getParameter( "passWord ");
ArrayList   arl   =   new   ArrayList();
String   strKengen   =   " ";
if   (strUserID   !=   null   &&   !strUserID.equals( " ")  
&&   strPassWord   !=   null   &&   !strPassWord.equals( " "))
{
LoginHelper   loginHelper=new   LoginHelper();
loginHelper.setStrUserID(strUserID);
loginHelper.setStrPassword(strPassWord);
boolean   blnRet   =   loginHelper.checkLogin();
strKengen   =   loginHelper.getStrKengen();
System.out.println(strKengen);
}
%>
document.forms[0].item( "txtKengen ").value   =   " <%=strKengen%> ";
return   true;
}
}
function   pageJump()   {
document.forms[0].item( "txtKengen ").value   =   " <%=strKengen%> ";
if   (document.forms[0].item( "txtKengen ").value   ==   "0 ")
{
alert( "密码不正确! ");
return;
}
if   (document.forms[0].item( "txtKengen ").value   ==   "-1 ")
{
alert( "用户不存在 ");
return;
}
if   (document.forms[0].item( "txtKengen ").value   ==   "1 ")
{
document.forms[0].action   =   "IppanUserMenu.jsp ";
}
if   (document.forms[0].item( "txtKengen ").value   ==   "2 ")
{
document.forms[0].action   =   "GroupUserMenu.jsp ";
}
if   (document.forms[0].item( "txtKengen ").value   ==   "3 ")
{
document.forms[0].action   =   "AllUserMenu.jsp ";
}
if   (document.forms[0].item( "txtKengen ").value   ==   "4 ")
{
document.forms[0].action   =   "OtherUserMenu.jsp ";
}
document.forms[0].submit();
}
</script>
<input   type= "button "   style= "width:   50;   height:   50;   border:   0; "   name   =   "btnLogin "   value= "登陆 "
onclick= "if   (check()   ==   true)   {form1.submit();pageJump();}   else   {return   false;} ">
<INPUT   type= "hidden "   name= "txtKengen "   value= "0 "/>

大家帮忙看看这段代码我写的对不对?我现在想实现的功能是先check用户和密码是不是空,如果都不是空,就去数据库里面检索,根据不同的返回值,跳转道不同的画面,或者弹出错误信息。但是现在用上面的代码check是没有问题,但是下面跳转就不对了,每次都是用上一次的返回值进行判断,那位大侠帮小弟看看到底问题出在什么地方,谢谢了。在线等!

------解决方案--------------------
为什么写这么复杂?

不要把java代码写在javascript里,因为,当加载这个jsp页面时,会先运行里面的java代码的(不