SSH 壞境搭建(3)_整合struts與spring

整合struts2與spring


1、在web.xml中配置spring監聽器

  <!-- 配置Spring的用於初始化 -->

		<listener>
		  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
		</listener>
		<context-param>
		  <param-name>contextConfigLocation</param-name>
		  <param-value>classpath:applicationContext*.xml</param-value>
		</context-param>

2、添加jar包struts2-spring-plugin-2.1.8.1.jar

3、修改strut.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" />
	<!-- 把擴展名配置爲action -->
	<constant name="struts.action.extension" value="action" />
	<!-- 把主題設置爲simple -->
	<constant name="struts.ui.theme" value="simple" />

	<package name="default" namespace="/" extends="struts-default">
		<action name="test" class="testAction">
			<result name="SUCCESS">/test.jsp</result>
		</action>
	</package>

</struts>

4、運行http://localhost:8080/TestSSH/test.action

wKioL1OEdNKA5bUwAAE4Bi9bluA628.jpg


就能夠整合strut2和spring

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章