spring 过了session时间后重新提交数据后全成乱码了,怎么办啊?

wenwen1 发布于 2013/03/22 22:41
阅读 449
收藏 1

当点开一个新增页面,并且填好了数据之后,但我没提交,如下图

然后等过一个小时后,我点提交按钮就跳转到登录页面,如下图

重新登录又会原始页面,如下图

但是这时点提交之后textarea里面的数据就成乱码了。如下图


如果没过session时间,就不会跳转到登录页面,也不会有乱码。

这是dao-context.xml里面的配置


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:jee="http://www.springframework.org/schema/jee" 
       xmlns:lang="http://www.springframework.org/schema/lang" 
       xmlns:security="http://www.springframework.org/schema/security" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       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.1.xsd        
                           http://www.springframework.org/schema/aop         
                           http://www.springframework.org/schema/aop/spring-aop-3.1.xsd     
                           http://www.springframework.org/schema/tx      
                           http://www.springframework.org/schema/tx/spring-tx-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/jee      
                           http://www.springframework.org/schema/jee/spring-jee-3.1.xsd         
                           http://www.springframework.org/schema/lang     
                           http://www.springframework.org/schema/lang/spring-lang-3.1.xsd     
                           http://www.springframework.org/schema/security      
                           http://www.springframework.org/schema/security/spring-security-3.1.xsd">




<!-- ******************************************************************** -->
<!-- Scan for dao layer annotated beans -->
<!-- ******************************************************************** -->
<context:component-scan base-package="bundles" scoped-proxy="interfaces"/>
<context:component-scan base-package="net.gvsun.dao" scoped-proxy="interfaces"/>

<!-- ******************************************************************** -->
<!-- Mark bean transactions as annotation driven -->
<!-- ******************************************************************** -->
<tx:annotation-driven transaction-manager="transactionManager"/>

<!-- ******************************************************************** -->
<!-- PropertyConfigurer for the DAO -->
<!-- ******************************************************************** -->
<context:property-placeholder location="classpath:gvsunxmgl-dao.properties"/>

<!-- ******************************************************************** -->
<!-- Setup the transaction manager -->
<!-- ******************************************************************** -->
<!-- Using Atomikos Transaction Manager -->
<bean class="com.atomikos.icatch.jta.UserTransactionManager" destroy-method="close" id="atomikosTransactionManager" init-method="init">
<property name="forceShutdown" value="true"/>
<property name="startupTransactionService" value="true"/>
<property name="transactionTimeout" value="60"/>
</bean>

<bean class="com.atomikos.icatch.jta.UserTransactionImp" id="atomikosUserTransaction"/>

<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
<property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION"/>
</bean>
<!-- Configure the Spring framework to use Json Support  -->    
<!--         <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" id="beanList">  
        <property name="messageConverters" ref="mappingJacksonHttpMessageConverter" />  
    </bean>    
    <bean id="mappingJacksonHttpMessageConverter"  
     class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />  -->

  <!-- ******************************************************************** -->
<!-- Setup a data source -->
<!-- ******************************************************************** -->
<!-- Using Apache DBCP Data Sources -->
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" name="xmglConnDS,springSecurityDataSource">
<property name="driverClassName" value="${xmglConn.connection.driver_class}"/>
<property name="username" value="${xmglConn.connection.username}"/>
<property name="password" value="${xmglConn.connection.password}"/>
<property name="url" value="${xmglConn.connection.url}"/>
<property name="maxIdle" value="${xmglConn.minPoolSize}"/>
<property name="maxActive" value="${xmglConn.maxPoolSize}"/>
</bean>

<!-- ******************************************************************** -->
<!-- Setup each persistence unit -->
<!-- ******************************************************************** -->

<!-- Configure a JPA vendor adapter -->
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" id="xmglConnJPAVendorAdapter">
<property name="showSql" value="${xmglConn.show_sql}"/>
<property name="generateDdl" value="${xmglConn.generateDdl}"/>
<property name="databasePlatform" value="${xmglConn.dialect}"/>
</bean>
<!-- EntityManager Factory that brings together the persistence unit, datasource, and JPA Vendor -->
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="xmglConn">
<property name="dataSource" ref="xmglConnDS"/>
<property name="persistenceUnitName" value="xmglConn"/>
<property name="jpaVendorAdapter" ref="xmglConnJPAVendorAdapter"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
<entry key="hibernate.connection.release_mode" value="on_close"/>
</map>
</property>
</bean>
</beans>

service-context.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:jee="http://www.springframework.org/schema/jee" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-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/jee 
http://www.springframework.org/schema/jee/spring-jee-3.1.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-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<context:annotation-config />  
      
<!-- ******************************************************************** -->
<!-- Scan for service layer annotated beans -->
<!-- ******************************************************************** -->
<context:component-scan base-package="net.gvsun.service" scoped-proxy="interfaces" />
<context:component-scan base-package="net.gvsun.xmgl.service" scoped-proxy="interfaces" />

<!-- ******************************************************************** -->
<!-- Mark bean transactions as annotation driven -->
<!-- ******************************************************************** -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 处理在类级别上的@RequestMapping注解-->  
    <bean  
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />  
    <!-- 处理方法级别上的@RequestMapping注解-->  
    <bean  
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >  
        <property name="messageConverters">    
            <util:list id="beanList">    
                <ref bean="mappingJacksonHttpMessageConverter"/>    
            </util:list>    
        </property>   
    </bean>  
    <!-- 视图解析器策略 和 视图解析器 -->
<!-- 对JSTL提供良好的支持 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/*" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 处理JSON数据转换的 -->
<bean id="mappingJacksonHttpMessageConverter" 
   class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> 
   <!-- 为了处理返回的JSON数据的编码,默认是ISO-88859-1的,这里把它设置为UTF-8,解决有乱码的情况 --> 
    <property name="supportedMediaTypes">  
        <list>  
           <value>text/html;charset=UTF-8</value>  
        </list>  
    </property>  
</bean>



</beans>


加载中
0
iuKa
iuKa
试试看spring的编码的filter呢
m
meng_you
好主意
0
dkz
dkz

在web.xml里面增加一个处理编码的filter

<filter>
    <filter-name>encodingFilter</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>
    <init-param>
       <param-name>forceEncoding</param-name>
       <param-value>true</param-value>
    </init-param>
</filter>
 
<filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

wenwen1
wenwen1
回复 @dkz : 这个我也加了,但是还是这样的。
dkz
dkz
回复 @wenwen1 : 登录的jsp文件里面加上编码设置 <%@ page language="java" contentType="text/html; charset=utf-8"%>
wenwen1
wenwen1
这个我已经加入过了。但是还是这样的。
0
t
toghraq

编码方式都设置成UTF-8  这样可以避免乱码:

数据库格式设置成utf8

servlet的获取数据编码 utf-8

服务器编码格式utf-8

0
m
meng_you
可以对session进行监听,如果避免乱码。可以现将工程改为UTF-8,然后页面的编码也是UTF-8,一般的就不会乱了,如果还有乱就进行编码与解码
返回顶部
顶部