Struts2的配置
展示了package的配置和constan的使用
<?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.configuration.xml.reload" value="true" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="myMessage" />
<constant name="struts.action.extension" value="do" />
<constant name="struts.multipart.saveDir" value="\tmp" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.multipart.maxSize" value="100000000" />
<package name="profile" extends="struts-default">
<action name="reg" class="Register">
<result name="success">/index.jsp</result>
<result name="input">/reg12.jsp</result>
</action>
<action name="user_*" class="userAction" method="{1}">
<result>/index.jsp</result>
<result name="login" type="redirectAction">user_toOpenBasic</result>
<result name="listProvince">/perfect.jsp</result>
<result name="finish">/dealwith.jsp</result>
<result name="fillinfo">/perfect.jsp</result>
<result name="addinfo" type="chain">user_toOpenBasic</result>
<result name="tobasic">/WEB-INF/basic.jsp</result>
<result name="tologin">/WEB-INF/tologin.jsp</result>
</action>
</package>
<package name="browser" namespace="/" extends="struts-default">
<action name="browser" class="browserAction">
<result name="ERROR">/error.jsp</result>
/action>
</package>
</struts>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<!--将spring这只在web.xml中 有web容器管理-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>serverName</param-name>
<param-value>http://localhost:8080/Profile/user_login.do</param-value>
</context-param>
<context-param>
<param-name>casServerLogoutUrl</param-name>
<param-value>http://localhost:8080/usercenter/logout</param-value>
</context-param>
<filter>
<filter-name>Character Encoding Filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Character Encoding Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 防注入式及XSS攻击 -->
<filter>
<filter-name>InjectFilter</filter-name>
<filter-class>com.profile.util.InjectFilter</filter-class>
<!-- filter word, split with blank -->
<init-param>
<param-name>invalidsql</param-name>
<param-value>select insert delete update create destory ‘</param-value>
</init-param>
<!-- error page -->
<init-param>
<param-name>error</param-name>
<param-value>/exception/errcon.jsp</param-value>
</init-param>
<!-- debug -->
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>InjectFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AdminFilter</filter-name>
<filter-class>com.profile.util.AdminFilter</filter-class>
<init-param>
<param-name>excludedPages</param-name>
<param-value>/admin_login.do</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AdminFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 用户登陆权限验证 -->
<filter>
<filter-name>OwnerFilter</filter-name>
<filter-class>com.profile.util.OwnerFilter</filter-class>
</filter>
<!-- 用于单点退出,该过滤器用于实现单点登出功能,可选配置 个人建议得配 -->
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
<!-- 该过滤器用于实现单点登出功能,可选配置。 -->
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 该过滤器负责用户的认证工作,必须启用它 -->
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>http://localhost:8080/usercenter</param-value>
<!-- 这里的server是服务端的IP -->
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
</filter>
<!-- 该过滤器负责对Ticket的校验工作,必须启用它 -->
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>http://localhost:8080/usercenter</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
</filter>
<!-- 该过滤器负责实现HttpServletRequest请求的包裹,比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名,可选配置。 -->
<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
</filter>
<!-- 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。 比如AssertionHolder.getAssertion().getPrincipal().getName()。 -->
<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
</filter>
<!-- 到此为止单点登录结束 以下为struts2的过滤配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>OwnerFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/user_login.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- struts2的过滤器结束 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.profile.util.SessionListener</listener-class>
</listener>
<!-- 以下为单点登录配置 用于单点退出,该过滤器用于实现单点登出功能,可选配置 -->
<servlet>
<servlet-name>CheckCodeServlet</servlet-name>
<servlet-class>com.profile.util.CaptchaImageCreateController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CheckCodeServlet</servlet-name>
<url-pattern>/code</url-pattern>
</servlet-mapping>
<!-- <servlet-mapping> <servlet-name>regiset</servlet-name> <url-pattern>reg12.jsp</url-pattern>
</servlet-mapping> -->
<welcome-file-list>
<welcome-file>/WEB-INF/basic.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/exception/error.jsp</location>
</error-page>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<!-- <error-page> <error-code>404</error-code> <location>/</location> </error-page> -->
</web-app>
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 定义数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123123</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!--下边试讲hibernate中的bean.cfg.xml文件进行注入-->
<value>com/profile/bean/Province.hbm.xml</value>
<value>com/profile/bean/City.hbm.xml</value>
</list>
</property>
</bean>
<!-- hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--这里是一个接口的注入-->
<bean id="userDao" class="com.profile.dao.impl.UserDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<!-- 浏览器检测 -->
<bean id="browserService" class="com.browser.util.BrowserServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>
<bean id="browserAction" class="com.browser.util.BrowserAction">
<property name="browserService">
<ref bean="browserService" />
</property>
</bean>
<!--下边是service的注入 其中每一个service都有一个属性userDao 就是上边注入配置的一个接口-->
<bean id="adminService" class="com.profile.service.impl.AdminServiceImpl">
<property name="userDao" ref="userDao" />
</bean>
<bean id="userService" class="com.profile.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao" />
</bean>
<!--这下边是 struts中注入的东西 userAction是action的名字 property是action中所拥有的属性 -->
<bean id="userAction" class="com.profile.action.UserAction" scope="prototype">
<property name="userService" ref="userService" />
<property name="cityService" ref="cityService" />
</bean>
<bean id="adminAction" class="com.profile.action.AdminAction"
scope="prototype">
<property name="userService" ref="userService" />
<property name="adminService" ref="adminService" />
<property name="browserService" ref="browserService" />
</bean>
</beans>
如果大家有兴趣可以到我的github上去下载:https://github.com/xuliugen/SSHFrameSet
时间: 2024-10-03 14:44:37