首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp、struts页面跳转有关问题

2012-02-19 
jsp、struts页面跳转问题登录与注册界面:1.先按下 登录 ,报 nouser ,再按下 注册 ,页面路径错误2.直

jsp、struts页面跳转问题
登录与注册界面:1.先按下 "登录 ",报 "no   user ",再按下 "注册 ",页面路径错误
                                2.直接按下 "注册 ",没有任何问题
      我写的代码如下:
                      1.jsp
                    <head> <title> <bean:message   key= "title "/> </title> </head>
<script   language= "javascript ">
function   login()
{
document.LoginForm.submit();
}
function   register()
{
window.location= "register.jsp ";
}
</script>
<body   background= "images/bg.gif ">
<html:form   action= "/LoginAction "   focus= "userName ">
<table   bgcolor= "aaff "   width= "100% "   >
<tr>
<td>
<bean:message   key= "userName "/> : <html:text   property= "userName "   name= "userName "   value= " "   size= "10 "/> &nbsp
<bean:message   key= "password "/> : <html:text   property= "password "   name= "password "   value= " "   size= "10 "/>
<logic:messagesPresent   message= "failLogin ">                                                
                        <html:errors   property= "loginFail "/>                                            
                        </logic:messagesPresent>                                        
<input   type= "button "   onclick= "login() "   value= " <bean:message   key= "submit "/> "   /> &nbsp
<input   type= "reset "   value= " <bean:message   key= "reset "/> "/> &nbsp
<input   type= "button "   onclick= "register() "   value= " <bean:message   key= "register "/> "/>
</td>
</tr>
</table>
</html:form>
</body>
 
              2.java--Action
                      public   ActionForward   execute(ActionMapping   mapping,ActionForm   actionForm,
HttpServletRequest   request,HttpServletResponse   response)
{
boolean   bool=false;

ActionErrors   errors=new   ActionErrors();
ActionForward   actionForward=new   ActionForward();

LoginForm   form=(LoginForm)actionForm;
LoginBean   loginBean=new   LoginBean(getDataSource(request,   "sqlServer "));
bool=loginBean.loginCheck(form.getUserName(),form.getPassword());



errors.add( "loginFail ",new   ActionMessage( "failLogin "));
        saveErrors(request,errors);
        actionForward=   mapping.findForward( "fail ");    
        if(bool==true)
{
actionForward=   mapping.findForward( "success ");

}      
        return   actionForward;
}

                3.struts-config.xml
                            <action-mappings>
        <action   path= "/LoginAction "  
        type= "javaStruts.action.LoginAction "
        name= "LoginForm "
        input= "/jsp/login.jsp "
        scope= "request "
        validate= "false ">        
        <forward   name= "success "   path= "/jsp/bb.jsp "/>
        <forward   name= "fail "   path= "/jsp/login.jsp "/>              
        </action>


           


[解决办法]
问题可能出现的原因:
在你的javascript里面,注册的脚本是这么写的:
function register(){
window.location= "register.jsp ";
}
而在你的配置文件里面,是这么写的
"/jsp/login.jsp "
可能在你登陆的时候,发现不对,在去注册的时候,那么跳转的目录就变成jsp下面了,这时,你把脚本里的URL这么写,试试:
window.location= " <%=request.getContextPath()%> /register.jsp ";
[解决办法]
试试
function register()
{
window.location= "register.jsp ";
}
window.location这里路径有问题,写完整

request.getContextPath()+ "/register.jsp "

热点排行