| 发表于: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> 而是显示空白页面呢?求解...... |
|
|
|
|