Spring Notes ⑥--Integration struts2

Source: Internet
Author: User

How spring is used in Web applications

    1. Additional JAR packages required

      spring-web-4.0.0

      spring-webmvc-4.0.0

    2. Spring configuration file, no different

?

Need to be configured under Web. XML, using myeclipse2014 to automatically generate

?

<!-- Start IOC container Servletcontextlin--

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</ Listener-class>

</listener>

?

<!-- Configuration Spring file location-

<context-param>

<param-name>contextconfiglocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

?

After the bean is configured

<body>

<%

//1. from Application An instance of an IOC container in a domain object

ApplicationContext ctx=webapplicationcontextutils.getwebapplicationcontext (application);

?

//2. from get bean in IOC container

Person P=ctx.getbean. class );

?

//3. Use Bean

P.hello ();

?

?

%>

?

?

How to integrate Struts2

Purpose: To enable the IOC container to manage the action of the STRUTS2

?

Configuring STRUTS2 's action in the spring IOC container

Note: When configuring the Struts2 action in the IOC container, the scope property must be configured with a value of prototype

<Beanid="Personservice"class="Com.test.spring_ Web.service.PersonService "></bean>

????

???? <beanid="Personaction"class="Com.test.spring_ Web.action.PersonAction "

???????? scope="prototype">

???????? <propertyname="Personservice"ref="Personservice" ></Property>

???? </Bean>

?

Configure the Struct2 configuration file; The Class property of the action node needs to point to the bean in the IOC container.

<actionname="Person-save"class="personaction">

???????? <result>/success.jsp</result>

???? </action>

?

Note the need to add files

?

Spring Notes ⑥--Integration struts2

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.