qq_28658245
qq_28658245
采纳率25%
2017-01-11 02:17 阅读 1.3k

tomcat7 get请求乱码,求大神解惑呀

在做一个项目时,get请求发送中文参数出现乱码,框架是ssh框架
已经设置了springMVC的过滤器,tomcat中server.xml也已经指定编码,jsp页面也指定了编码,但是发送get请求是还是乱码

web.xml

 <web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/applicationContext*.xml</param-value>
  </context-param>
  <filter>
    <filter-name>encoding</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>encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>Spring OpenSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
      <param-name>sessionFactoryBean</param-name>
      <param-value>sessionFactory</param-value>
    </init-param>
    <init-param>
      <param-name>flushMode</param-name>
      <param-value>ALWAYS</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>Spring OpenSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping> 
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/SpringMVC*.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

server.xml

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8"
               useBodyEncodingForURI="true"/>

jsp:

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • bjjoy2009 迷茫猿小明 2017-01-11 02:22

    这个get需要添加编码,在发送请求的地方把中文参数staff改为encodeURI(encodeURI(staff)),
    在后台处理的地方进行解码,URLDecoder.decode(staff,"UTF-8")

    点赞 评论 复制链接分享
  • shao861210 Hi少帮主 2017-01-11 02:50

    这个get需要添加编码,在发送请求的地方把中文参数staff改为encodeURI(encodeURI(staff)),
    在后台处理的地方进行解码,URLDecoder.decode(staff,"UTF-8");楼上正解

    点赞 评论 复制链接分享

相关推荐