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

struts页面跳转有关问题

2012-04-03 
struts页面跳转问题struts-config.xml?xmlversion 1.0 encoding UTF-8 ?!DOCTYPEstruts-configPU

struts页面跳转问题
struts-config.xml
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   struts-config   PUBLIC   "-//Apache   Software   Foundation//DTD   Struts   Configuration   1.2//EN "   "http://struts.apache.org/dtds/struts-config_1_2.dtd ">

<struts-config>
    <data-sources   />
    <form-beans>  
<form-bean   name= "loginForm "   type= "chojo.struts.form.LoginForm "   />  
    </form-beans>  
    <global-exceptions   />
    <global-forwards   >
<forword   name= "ToErrorPage "   path= "/common/messagepage.jsp "/>
    </global-forwards   >
    <action-mappings>  
<action   path= "/login "  
type= "chojo.struts.action.LoginAction "
name= "loginForm "  
scope= "request "  
validate= "true "
input= "/index.jsp ">  
<forword   name= "ToUserPage "   path= "/admin/userinfo.jsp "/>
</action>
    </action-mappings>  
    <message-resources   parameter= "chojo.ApplicationResources_zh "   />
</struts-config>  

index.jsp

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN ">
<head> <title> chojoinfosystem </title> </head>
<%@   include   file= "/common/taglibs.jsp "%> <head>

<html:html>
<META   http-equiv=Content-Type   content= "text/html;   charset=shift_jis "> </HEAD>
<body>
<html:form     action   =   "login.do "   focus   =   "adminid "   method   =   "post ">
<table   align= "center ">
<tr> <td> username </td> <td> <html:text   property= "adminid "   size= "10 "/> </td> </tr>
<tr> <td> password </td> <td> <html:password   property= "password "   size= "11 "/> </td> </tr>
</table>
    <table   align= "center "   valign= "top "   height= "40 "   cellspacing= "0 "   cellpadding= "0 "   border= "0 ">
<tr>
<td> <html:submit   property= "submit "> login </html:submit> </td>
<td> <html:reset> reset </html:reset> </td>
</tr>
    </table>
</html:form>
</body>
</html:html>

LoginAction.java

public   class   LoginAction   extends   Action   {
public   ActionForward   execute(ActionMapping   mapping,   ActionForm   actionForm,  
HttpServletRequest   request,   HttpServletResponse   response)   throws   Exception   {  
String   PageForward   =   "ToErrorPage ";
HttpSession   session   =   request.getSession(true);
ActionMessages   errors   =   new   ActionMessages();



LoginForm   loginForm   =   (LoginForm)actionForm;
String   name   =   loginForm.getAdminid();  
String   pwd   =   loginForm.getPassword();  
Connection   conn   =   DbConnection.getConnection();

System.out.println( "name   =   "+name+ "   ,   pwd   =   "+pwd);  

if(UserCheck(conn,name,pwd)){
PageForward   =   "ToUserPage ";
}else{
errors.add(ActionMessages.GLOBAL_MESSAGE,new   ActionMessage( "error.admin.accessDeny "));
if(!errors.isEmpty()){
saveErrors(request,errors);
}
}
System.out.println(PageForward);
return   mapping.findForward(PageForward);  
}

private   boolean   UserCheck(Connection   Conn,   String   name,   String   pwd)   {
Connection   conn   =   Conn;
PreparedStatement   stmt   =   null;
ResultSet   rs   =   null;
String   sql   =   "SELECT   *   FROM   admin   WHERE   adminid   =   ?   AND   password   =   ?   ";

try   {
stmt   =   conn.prepareStatement(sql);
stmt.setString(1,   name);
stmt.setString(2,   pwd);
rs   =   stmt.executeQuery();
if(rs.next()){
return   true;
}
}   catch   (SQLException   e)   {
e.printStackTrace();
}finally{
if(rs   !=   null){
try   {
rs.close();
}   catch   (SQLException   e)   {
e.printStackTrace();
}
}
if(stmt   !=   null){
try   {
stmt.close();
}   catch   (SQLException   e)   {
e.printStackTrace();
}
}
}
return   false;
}  
}

问题:return   mapping.findForward(PageForward);   返回的是null
PageForward   =   "ToUserPage ";已经正常执行了,为什么点login后,页面不跳转到userinfo.jsp
<%@   page   contentType= "text/html;charset=gb2312 "   language= "java "%>
<%@   include   file= "/common/taglibs.jsp "%> <head>
<title>
success
</title>
</head>
<html:html>
<body>
connection.............................
</body>
</html:html>
而是显示空白页面呢?求解......

[解决办法]
请检查你的struct-config.xml
我怎么看见你写的是:
<forword name= "ToUserPage " path= "/admin/userinfo.jsp "/>
应该是
<forward name= "ToUserPage " path= "/admin/userinfo.jsp "/> 吧??
仔细仔细再仔细啊
[解决办法]
楼主拜托了,明明是你写的错误啊,还说人家忽悠你啊 你把forward 写成forword了

热点排行