I. Structure of the project
Second, the new useraction, inherit from the Actionsupport, and implement the Modeldriven<user> interface; Getmodel method is used to assemble object properties; Note that The UserService field name is the same as the ID name in the UserService bean configured in Applicationcontext.xml
Packagecom.hjp.action;ImportCom.hjp.domain.User;ImportCom.hjp.service.UserService;ImportCom.opensymphony.xwork2.ActionSupport;ImportCom.opensymphony.xwork2.ModelDriven;/*** Created by Jiapeng on 2015/12/13.*/ Public classUseractionextendsActionsupportImplementsModeldriven<user>{User User=NewUser (); @Override PublicUser Getmodel () {returnuser; } PrivateUserService UserService; Public voidSetuserservice (UserService userservice) { This. UserService =UserService; } PublicString Register () {userservice.register (user); returnSUCCESS; }}
useraction
Third, the new index.jsp file, the code is as follows
<%-- Created by IntelliJ. User:jiapeng Date: 2015/12/13 time: 11:36 this template Use File | Settings | File Templates. --%><%@ page contenttype= "Text/html;charset=utf-8" language= "java"%> user name: <input type=" text "name=" username "/>< Br/> password: <input type= "password" name= "password"/><br/> Age: <input type= "text" Name= "ages"/><br/> <input type= "Submit" value= "register"/></form>< ;/body>
index.jsp
Iv. new Struts.xml file, and message.jsp file
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" "Http://struts.a Pache.org/dtds/struts-2.3.dtd "><Struts> <!--Constants - <constantname= "Struts.devmode"value= "true"></constant> <!--Package - < Packagename= "Hello"namespace="/"extends= "Struts-default"> <Actionname= "Useraction_*"class= "Com.hjp.action.UserAction"Method= "{1}"> <resultname= "Success">/message.jsp</result> </Action> </ Package></Struts>
Struts.xml
<%-- Created by IntelliJ idea. User:jiapeng 2015/12/13 16:23 This template use File | Settings | File Templates. --%><%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>Success! </body>
message.jspV. Configuring the Web. xml file, mainly configuring spring and struts
<?XML version= "1.0" encoding= "UTF-8"?><Web-appxmlns= "Http://xmlns.jcp.org/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version= "3.1"> <!--Spring - <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:applicationContext.xml</Param-value> </Context-param> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <!--Struts - <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>
Web. XMLSpring integration of SSH Integration Spring (cont.)