spring_day4_03-ssh整合(struts2整合spring)

来源:互联网 发布:网络统考报名修改密码 编辑:程序博客网 时间:2024/06/09 21:16

项目结构:



/spring_day04_sshdemo1/WebContent/WEB-INF/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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  <display-name>spring_day04_sshdemo1</display-name>    <context-param>  <param-name>contextConfigLocation</param-name>  <param-value>classpath:spring3.xml</param-value>  </context-param>    <!-- 过滤器 start -->  <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>    <!-- 过滤器 end -->      <!-- 监听器 -->  <listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>    <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list></web-app>

/spring_day04_sshdemo1/src/struts.xml

<?xml version="1.0" encoding="UTF-8"?><!-- struts2约束 start --><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><!-- struts2约束 end --><struts><package name="demo1" extends="struts-default" namespace="/"><!-- class属性里面不写action全路径,因为写,action对象就创建两次写spring配置的action的bean的id值 --><action name="userAction" class="userAction"></action></package></struts>

/spring_day04_sshdemo1/src/spring3.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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"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/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 配置c3p0连接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"></property><!-- & 需要转义成 & --><property name="jdbcUrl" value="jdbc:mysql://*.36.138:3306/spring_day04?userUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull" /><property name="user" value="root"></property><property name="password" value="*"></property></bean><!-- 配置action对象 --><bean id="userAction" class="com.hlg.action.UserAction" scope="prototype"></bean></beans>

com.hlg.action.UserAction

package com.hlg.action;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {public String execute(){System.out.println("struts2整合spring成功....");return NONE;}}


访问:http://localhost:8080/spring_day04_sshdemo1/userAction.action