| 发表于:2007-04-24 18:38:41 楼主 |
我做的是一个简单的ssh的小例子,是从网上找的,但是总也调不通,好像是找不到action 但我也找不出错误,请大家看看,我是用myeclipse配置的环境 我没有进行数据库联接,没有用到hibernate 首先是jsp页面 login.jsp <%@ page language= "java " pageencoding= "utf-8 "%> <%@ taglib uri= "http://struts.apache.org/tags-bean " prefix= "bean " %> <%@ taglib uri= "http://struts.apache.org/tags-html " prefix= "html " %> <%@ taglib uri= "http://struts.apache.org/tags-logic " prefix= "logic " %> <%@ taglib uri= "http://struts.apache.org/tags-tiles " prefix= "tiles " %> <!doctype html public "-//w3c//dtd html 4.01 transitional//en "> <html:html lang= "true "> <head> <html:base /> <title> login.jsp </title> </head> <body> <html:form action= "login.do " method= "post " focus= "login "> <table border= "0 " align = "center "> <tr> <td> login: </td> <td> <html:text property= "username " /> </td> </tr> <tr> <td> password: </td> <td> <html:password property= "password " /> </td> </tr> <tr> <td colspan= "2 " align= "center "> <html:submit /> </td> </tr> </table> </html:form> </body> </html:html> 然后是 actionform /* * generated by myeclipse struts * template path: templates/java/javaclass.vtl */ package com.form; import javax.servlet.http.httpservletrequest; import org.apache.struts.action.actionerrors; import org.apache.struts.action.actionform; import org.apache.struts.action.actionmapping; /** * myeclipse struts * creation date: 04-24-2007 * * xdoclet definition: * @struts.form name= "loginform " */ public class loginform extends actionform { /* * generated fields */ /** password property */ private string password; /** username property */ private string username; /* * generated methods */ /** * method validate * @param mapping * @param request * @return actionerrors */ public actionerrors validate(actionmapping mapping, httpservletrequest request) { // todo auto-generated method stub return null; } /** * method reset * @param mapping * @param request */ public void reset(actionmapping mapping, httpservletrequest request) { username = null; password = null; } /** * returns the password. * @return string */ public string getpassword() { return password; } /** * set the password. * @param password the password to set */ public void setpassword(string password) { this.password = password; } /** * returns the username. * @return string */ public string getusername() { return username; } /** * set the username. * @param username the username to set */ public void setusername(string username) { this.username = username; } } 在然后是action /* * generated by myeclipse struts * template path: templates/java/javaclass.vtl */ package com.action; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts.action.action; import org.apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionmapping; import com.form.loginform; /** * myeclipse struts * creation date: 04-24-2007 * * xdoclet definition: * @struts.action path= "/login " name= "loginform " input= "/login.jsp " scope= "request " validate= "true " * @struts.action-forward name= "loginsuccess " path= "/mainmenu.jsp " */ public class loginaction extends action { /* * generated methods */ /** * method EXECute * @param mapping * @param form * @param request * @param response * @return actionforward */ public actionforward EXECute(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) { loginform loginform = (loginform) form;// todo auto-generated method stub string username=loginform.getusername(); string password=loginform.getpassword(); if(username.equals( "test ")&&password.equals( "test ")){ return mapping.findforward( "loginsuccess "); }else{ return mapping.getinputforward(); } } } 最后是配置文件 applicationcontext.xml <?xml version= "1.0 " encoding= "utf-8 "?> <!doctype beans public "-//spring//dtd bean//en " "http://www.springframework.org/dtd/spring-beans.dtd "> <beans> <bean name= "/login " class= "com.action.loginaction " singleton= "false "> </bean> </beans> //////////然后是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= "com.form.loginform " /> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action attribute= "loginform " input= "/login.jsp " name= "loginform " path= "/login " scope= "request " type= "org.springframework.web.struts.delegatingactionproxy "> <forward name= "loginsuccess " path= "/mainmenu.jsp " /> </action> </action-mappings> <message-resources parameter= "com.test.struts.applicationresources " /> <plug-in classname= "org.springframework.web.struts.contextloaderplugin "> <set-property property= "contextconfiglocation " value= "/web-inf/applicationcontext.xml " /> </plug-in> </struts-config> 运行后就是提示找不到action,无法进入mainmenu.jsp,所有的包,插件我都导了进来,请大家看看是哪里的问题,谢谢了!!!! |
|
|
|
|