struts2+spring3+hibernate3+ireport+防止重复登录

1、首先是配置 

      1)web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
        <!--这里建两个配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>

                     <!--这个位于src下,主要是事务及连接池的一些配置-->
classpath:applicationContext-business.xml

                   <!--这个是我们常见的spring配置文件,默认在webroot下面,主要是数据源与防止重复登录的一些配置-->
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
                <!--下面的配置将对防止重复登陆功能起作用,过滤并转发请求-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>

2)struts配置(因为程序中使用了注解,所以这里除了保留报表的配置外,其他全部使用注解处理业务)

<?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>
<package name="default" extends="struts-default,jasperreports-default">
<action name="user_report" class="action.IreportAction" method="ireport">
<result name="success" type="jasper">
<param name="location">/ireport/user.jasper</param>
<param name="dataSource">list</param>
<param name="format">PDF</param>
</result>
</action>
</package>
</struts>

3)spring配置

1、applicationContext-business.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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/aop     
   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  http://www.springframework.org/schema/beans     
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
     http://www.springframework.org/schema/context   
  http://www.springframework.org/schema/context/spring-context-2.5.xsd   
  http://www.springframework.org/schema/tx     
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<context:annotation-config />
<context:component-scan base-package="*" />
<aop:aspectj-autoproxy />
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor">
</bean>


<tx:annotation-driven transaction-manager="transactionManager" />

<!-- 创建session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 将数据源注入到工厂 -->
<property name="dataSource" ref="dataSource" />
<!-- 实体bean的映射文件 -->
<property name="mappingResources">
<list>
<value>bean/User.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- c3p0连接池配置 -->
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.c3p0.max_size">50</prop>
<prop key="hibernate.c3p0.min_size">50</prop>
<prop key="hibernate.c3p0.timeout">120</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.idle_test_period">120</prop>
<prop key="hibernate.c3p0.acquire_increment">2</prop>
<prop key="myeclipse.connection.profile">hl3000</prop>
</props>
</property>
</bean>
<!-- 创建事务  -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>

2、applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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-3.0.xsd
                        http://www.springframework.org/schema/security 
                        http://www.springframework.org/schema/security/spring-security-3.0.xsd">


<http auto-config="true">
<!-- <intercept-url pattern="/**" access="ROLE_USER" />
登录页面为/login.jsp,登录成功页面为/main.jsp,通过/product.action映射过去,且总是用这个页面为登录成功页面 -->
<form-login login-page="/login.jsp"
authentication-failure-url="/login.jsp?error=true"
default-target-url="/main.jsp"
always-use-default-target="true" />

<!-- 如果第二次登录,阻止,并显示错误信息 -->
<session-management invalid-session-url="/error.jsp">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="false" />
</session-management>
</http>

<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password,enabled from t_user where username=?"
authorities-by-username-query="select username,role from t_user where username=?" />
</authentication-provider>
</authentication-manager>

                 <!--创建数据源-->
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<beans:property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl" />
<beans:property name="username" value="scott" />
<beans:property name="password" value="tiger" />
</beans:bean>
</beans:beans>

2、文件位置及jar包(见相册:struts2+spring3+hibernate3+ireport+防止重复登录)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值