Spring integration of SSH Integration Spring (cont.)

Source: Internet
Author: User

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.jsp

V. 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. XML

Spring integration of SSH Integration Spring (cont.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.