日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Spring整合Struts2

發布時間:2023/11/27 生活经验 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring整合Struts2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

①導入Struts2 jar包

②在web.xml文件中創建過濾器

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name></display-name>    <!-- 配置struts2 的filter --><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><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>

③創建Struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><constant name="struts.enable.DynamicMethodInvocation" value="false" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default"><!--  Spring 整合 Struts2 時, 在 Struts2 中配置的 Spring 的 Action 的 class 需要指向 IOC 容器中該 bean 的 id--><action name="person-save" class="personAction"><result>/success.jsp</result></action></package></struts>

④創建PersonService類

public class PersonService {public void save(){System.out.println("person's save.....");}}

⑤創建PersonAction類

import com.atguigu.spring.struts.service.PersonService;public class PersonAction {private PersonService personService;public void setPersonService(PersonService personService) {this.personService = personService;}public String execute(){System.out.println("execute.....");return "SUCCESS";}}

⑥導入Spring的jar包

⑦創建applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"><bean id="person" class="com.atguigu.spring.struts.beans.Person"><property name="username" value="spring"></property></bean><bean id="personService" class="com.atguigu.spring.struts.service.PersonService"></bean><!-- 注意在IOC容器中配置Struts2的Action時組要配置scope屬性 --><bean id="personAction" class="com.atguigu.spring.struts.actions.PersonAction" scope="prototype"><property name="personService" ref="personService"></property></bean></beans>

⑧導入一個jar包——struts2-spring-plugin-2.3.15.3.jar

?

OK!

?

轉載于:https://www.cnblogs.com/sdnu-zhang/p/8528417.html

總結

以上是生活随笔為你收集整理的Spring整合Struts2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。