1, open MyEclipse, add WebProject, name is TestStruts2
2. Configure the Tomcat environment.
1) Find tomcat6.x under Windows-Preferences--myeclipse--servers
2) Select Enable, browse to find the local Tomcat6 file location
3) Locate the Tomcat--conf--server.xml file and add it before the </Host> end tag
<path= "/teststruts2" docBase= "E:\software\MyEclipseWorkSpaces\ Teststruts2\webroot " reloadable=" true "/>
3. Introduction of JAR Package
4. Configure Web. xml
<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "2.4"xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <Filter> <Filter-name>Struts2</Filter-name> <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Struts2</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping></Web-app>
5, under the SRC path to establish struts.xml
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" "Http://struts.apache.or G/dtds/struts-2.3.dtd "> <Struts> < Packagename= "TestStruts2"extends= "Struts-default"namespace=""> <Actionname= "Login"class= "Com.test.action.LoginAction"> <resultname= "Success">/result.jsp</result> </Action> </ Package> </Struts>
6. Create a class file under the SRC path
Packagecom.test.action;ImportCom.opensymphony.xwork2.ActionSupport; Public classLoginactionextendsactionsupport{Private Static Final LongSerialversionuid = -74906200993380354l; PrivateString username; PrivateString password; PublicString GetUserName () {returnusername; } Public voidSetusername (String username) { This. Username =username; } PublicString GetPassword () {returnpassword; } Public voidSetPassword (String password) { This. Password =password; } PublicString Execute ()throwsException {return"Success"; }}
7, under the Webroot path new login.jsp, result.jsp to test
/** * login.jsp */ <form action= "Login" method= "POST" > Username:<input type= "text" name= "username" ><br > Password:<input type= "text" name= "password" > <input type= "Submit" value= "Submit" > </form>/*** result.jsp **/ username:${ Requestscope.username}<br> Password:${requestscope.password}
Java Learning Notes (1)--strut2.3.24 Environment Building