您的位置:程序门 -> java -> web 开发



struts页面跳转问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


struts页面跳转问题[已结贴,结贴人:lyz1545]
发表于:2007-09-23 00:56:52 楼主
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>
而是显示空白页面呢?求解......
发表于:2007-09-23 10:25:361楼 得分:0
没有人帮忙看看么?   郁闷......
发表于:2007-09-23 13:58:142楼 得分:0
return   mapping.findforward(touserpage);就可以了,你要用定好的名字啊
发表于:2007-09-23 15:22:023楼 得分:0
非也
发表于:2007-09-23 16:18:384楼 得分:15
请检查你的struct-config.xml
我怎么看见你写的是:
<forword   name= "touserpage "   path= "/admin/userinfo.jsp "/>
应该是
<forward   name= "touserpage "   path= "/admin/userinfo.jsp "/> 吧??
  仔细仔细再仔细啊
发表于:2007-09-23 23:42:365楼 得分:0
在配置中少 <forward   name= "toerrorpage "   path= "/admin/worry.jsp "/>
发表于:2007-09-23 23:50:066楼 得分:0
将表单提交改下 <input   type=“type”   value=“提交”> 试试
发表于:2007-09-24 09:13:517楼 得分:0
四楼的忽悠我   ,你写的和我写的一样啊,没看出不同.5楼的那段代码我加了,你再仔细看看   :(   ,
六楼的   我想用sturts框架   ,你那种是不大对吧   .还有人帮忙找错么......
现在迁移显示的是   http://localhost:8080/webroot/login.do     但页面是空白的.没有显示出userinfo.jsp上的东西
发表于:2007-09-24 09:19:128楼 得分:0
你的代码里有问题,抛了检查你的代码,不然把错误信息列出来,估计form错不了,看看你的bean或jsp页面
发表于:2007-09-24 10:10:479楼 得分:5
楼主拜托了,明明是你写的错误啊,还说人家忽悠你啊   你把forward   写成forword了
发表于:2007-09-24 10:21:3510楼 得分:0
大汗......     首先向四楼的郑重道歉和感谢   .同时感谢9楼的   朋友   此贴可以结束了   送分,虽然少了点,但是一点心意


快速检索

最新资讯
热门点击