SSH配置

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" version="3.0">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <error-page>
    <error-code>404</error-code>
    <location>/404error.jsp</location>
  </error-page>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
  <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>
</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" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:faces="http://www.springframework.org/schema/faces" xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
xmlns:sec="http://www.springframework.org/schema/security" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:ws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.0-m1.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- 配置自动扫描的包 -->
<context:component-scan
base-package="com.xxx.action"></context:component-scan>


<!-- 配置数据源 -->
<!-- 1.导入数据源 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 配置主库数据源bean -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 使用外部化属性文件的属性 -->
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<!-- 若数据库中连接数不足时一次向数据库服务器申请多少个连接 -->
<property name="acquireIncrement" value="${acquireIncrement}"></property>
<!-- 初始化数据库连接池时连接的数量 -->
<property name="initialPoolSize" value="${initialPoolSize}"></property>
<!-- 数据库连接池中最小的连接数 -->
<property name="minPoolSize" value="${minPoolSize}"></property>
<!-- 数据库连接池中最大的连接数 -->
<property name="maxPoolSize" value="${maxPoolSize}"></property>
<!-- C3P0数据库连接池可以维护Statement的个数 -->
<property name="maxStatements" value="${maxStatements}"></property>
<!-- 每个连接同时可以使用Statement对象的个数 -->
<property name="maxStatementsPerConnection" value="${maxStatementsPerConnection}"></property>
</bean>
<!-- 配置 SessionFactory是Spring整合hibernate的核心入口 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 映射目录路径 -->
<property name="mappingLocations">
<list>
<value>classpath:com/xx/model/*.hbm.xml</value>
<value>classpath:com/xx/model/*.hbm.xml</value>
<value>classpath:com/xx/model/*.hbm.xml</value>
</list>
</property>
</bean>


<!-- 配置Spring 的声明式事物 用来在service层面上实现事物管理,达到平台无关性 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>


<!-- 配置事物通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 写操作:isolation="DEFAULT"使用数据库的默认隔离级别 -->
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="batch*" propagation="REQUIRED" isolation="DEFAULT" />

<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" />
</tx:attributes>
</tx:advice>


<!-- 配置aop -->
<aop:config>
<!-- 事物的切入点通知 order="1"配置拦截优先级值越大优先级越低 -->
<aop:advisor pointcut="execution(* *..*Service.*(..))"
advice-ref="txAdvice" />
</aop:config>
</beans>

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.ui.theme" value="simple"></constant>
<!-- 开发模式 -->
<constant name="struts.devMode" value="true"></constant>
<!-- 开启OJNL对静态方法的访问 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<!-- 继承jfreechart-default包以使生成的分析图表 直接输出到客户端-->
<package name="surveyparkPkg" extends="struts-default,jfreechart-default,json-default" namespace="/">
<interceptors>
<!-- 注册登录拦截器RightFilterInterceptor.java -->
<interceptor name="rightFilterInterceptor" class="com.sopo.ssh.struts2.interceptor.RightFilterInterceptor"></interceptor>
<!-- 定义拦截器栈 -->
<interceptor-stack name="surveyparkStack">
<interceptor-ref name="rightFilterInterceptor"></interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack">
<!-- 使用刷新机制,不再提前利用prepare赋值,而是在后置处理时刷新对象,将newmodel把栈顶对象oldmodel替换 -->
<param name="modelDriven.refreshModelBeforeResult">true</param>
<!-- 限制文件的上传大小6M -->
<param name="fileUpload.maximumSize">6291456</param>
<!-- 限制整个项目文件上传的总大小,默认为2M,此设置为6G -->
<param name="struts.multipart.maxSize">6442450944</param>
<!-- 限制文件扩展名 如果allowedTypes参数有配置,那么allowedExtensions参数将不会再起效。-->
<param name="fileUpload.allowedExtensions">.xlsx,.xls</param>
<!-- 限制文件的内容类型 
<param name="fileUpload.allowedTypes">application/vnd.openxmlformats-officedocument.spreadsheetml.shee,text/xml,application/excel,image/jpg,image/jpeg,image/png,image/gif,image/bmp</param>
-->
</interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- 定义默认站,这样就不用在每个Action中单独制定拦截器 -->
<default-interceptor-ref name="surveyparkStack"></default-interceptor-ref>
<!-- 配置全局的结果集 -->
<global-results>
<result name="login">/login.jsp</result>
<result name="error_no_right">/index.jsp</result>
<result name="errorPage">/errorPage.jsp</result>
<result name="notDataPage">/notDataPage.jsp</result>
</global-results>

<!-- loginAction -->
<action name="LoginAction_*" class="loginAction" method="{1}">
<result name="success">mainmemu.jsp</result>
<result name="loginPage">/login.jsp</result>
<result name="input">/login.jsp</result>
<result name="editUserPwd">/basic/authoritySet/userEditPwd.jsp</result> 
</action>

<!-- 下载 -->
<action name="UploadFileAction_downFile"  class="uploadFileAction" method="downFile">
<result type="stream">
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;fileName="${fileNamedown}"</param>
<param name="contentType">application/octet-stream</param>
<param name="bufferSize">1024</param>
</result>
</action>

<!-- 404-->
<package name="default" extends="struts-default">
<default-action-ref name="notFound" />
<action name="notFound">
<result>/error/404.jsp</result>
</action>
</package>

</struts>

hibernate.cfg.xml:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>
<session-factory>
<!--整合spring所需-->
<property name="javax.persistence.validation.mode">
none
</property>
<!-- 配置hibernate 的基本属性 -->
<!-- 1.数据源需要配置到IOC 容器中,所以此处不再配置数据源 -->
<!-- 2.关联的.hbm.xml也在IOC 容器配置sessionFactory 实例中配置 -->
<!-- 3.配置hibernate 的基本属性:方言, sql 显示及风格,生成数据表的策略以及二级缓存等。 -->
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>


<!-- 运行时是否打印 SQL -->
<property name="hibernate.show_sql">false</property>


<!-- 运行时是否格式化 SQL -->
<property name="hibernate.format_sql">true</property>


<!-- 生成数据表的策略 -->
<property name="hibernate.hbm2ddl.auto">update</property>






<!-- 设置 Hibernate 的事务隔离级别 -->
<property name="connection.isolation">2</property>


<!-- 删除对象后, 使其 OID 置为 null -->
<property name="use_identifier_rollback">true</property>

<!-- 设定 JDBC 的 Statement 读取数据的时候每次从数据库中取出的记录条数 -->
<property name="hibernate.jdbc.fetch_size">100</property>

<!-- 设定对数据库进行批量删除,批量更新和批量插入的时候的批次大小 -->
<property name="hibernate.jdbc.batch_size">30</property>

<!-- 二级缓存相关 log4j-1.2.17.jar
log4j-api-2.2.jar
log4j-core-2.2.jar-->
</session-factory>


</hibernate-configuration>

登录拦截器

public class RightFilterInterceptor implements Interceptor {

private static final long serialVersionUID = 1L;
public void destroy() {
}

public void init() {
}

public String intercept(ActionInvocation arg0) throws Exception {
BaseAction action = (BaseAction) arg0.getAction();
ActionProxy proxy = arg0.getProxy();
String ns = proxy.getNamespace();
String actionName = proxy.getActionName();
if (ValidateUtil.hasRight(ServletActionContext.getRequest(), ns,
actionName, action)) {
return arg0.invoke();
} else {
return "login";
}
}

}

action上的注解

@Scope("prototype")
@Controller

public class LoginAction extends BaseAction<User> implements SessionAware,
ServletRequestAware,ServletResponseAware {

@Resource

private UserService userService;

Service上:

@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements
UserService {

@Resource(name = "userDao")
public void setDao(BaseDao<User> dao) {
// TODO Auto-generated method stub
super.setDao(dao);
}

Dao上:

@Repository("userDao")











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值