Struts2 Spring集成的架构分析

Struts2 Spring集成架构图
Struts2 Spring集成结构图
1.请求页、响应页

</head>
<body>

   <h1>Hello World From Struts2 - Spring integration</h1>

   <s:form>
      <s:textfield name="firstName" label="First Name"/><br/>
      <s:textfield name="lastName" label="Last Name"/><br/>
   </s:form>
	
</body>

2.响应类

package cn.w3cschool.struts2;

public class User {
   private String firstName;
   private String lastName;

   public String execute()
   {
      return "success";
   }

   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }
}

3.http服务器配置文件(web.xml)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	
   <display-name>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>

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

   <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
         org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
   </filter>

   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

</web-app>

4.spring配置文件(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 id="userClass" class="cn.w3cschool.struts2.User">
      <property name="firstName" value="Michael" />
      <property name="lastName" value="Jackson" />
   </bean>
</beans>

5.struts2的配置文件(struts.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
   <constant name="struts.devMode" value="true" />
   <package name="helloworld" extends="struts-default">
      <action name="user" class="userClass" 
         method="execute">
         <result name="success">/User.jsp</result>
      </action>
   </package>
</struts>

6.运行效果
struts+spring架构分析

猜你喜欢

转载自blog.csdn.net/xie__jin__cheng/article/details/89510902