论坛首页 Java企业应用论坛

ssh jsp传值到struts2 为乱码 jsp显示正常 求教高手

浏览 2909 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-11-29   最后修改:2012-11-29
ssh jsp传值到struts2 为乱码 后台传值到jsp显示正常
jsp 头部<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
web.xml拦截器:
<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>
项目也是UTF-8编码的
求教高手破解??
   发表时间:2012-11-29  
我是高手,我来啦!
不过这种问题早就不是问题了,高手还是不出手好了。
0 请登录后投票
   发表时间:2012-11-29  
兄弟你问题描述的不够清楚。告诉我你是用什么方式提交到后台的?
0 请登录后投票
   发表时间:2012-11-30  
post 传值
<a href="show?title=<s:property value="title" />"><s:property value="title" /></a>
0 请登录后投票
   发表时间:2012-12-05  
写一个SetEndinng编码类继承Filter
package city.comm;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


public class SetEndinng implements Filter {   

    protected String encoding = null;    
    protected FilterConfig filterConfig = null;    
    protected boolean ignore = true;   
  
      
    public void destroy() {     
        this.encoding = null;   
        this.filterConfig = null;     
    }   
  
      
    public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
   
        if (ignore || (request.getCharacterEncoding() == null)) {   
            String encoding = selectEncoding(request);   
            if (encoding != null)   
                request.setCharacterEncoding(encoding);   
        }     

        chain.doFilter(request, response);   
    }   
  
      
    public void init(FilterConfig filterConfig) throws ServletException {     
        this.filterConfig = filterConfig;   
        this.encoding = filterConfig.getInitParameter("encoding");   
        String value = filterConfig.getInitParameter("ignore");   
        if (value == null)   
            this.ignore = true;   
        else if (value.equalsIgnoreCase("true"))   
            this.ignore = true;   
        else if (value.equalsIgnoreCase("yes"))   
            this.ignore = true;   
        else  
            this.ignore = false;     
    }     
    protected String selectEncoding(ServletRequest request) {     
        return (this.encoding);    
    }     
}

然后在web.xml配置文件里配置<filter>
          <filter-name>ChineseFilter</filter-name>
          <filter-class>far.comm.SetEndinng</filter-class>
          <init-param>
              <param-name>encoding</param-name>
              <param-value>UTF-8</param-value>
          </init-param>
    </filter>
    <filter-mapping>
          <filter-name>ChineseFilter</filter-name>
          <url-pattern>/*</url-pattern>
    </filter-mapping>
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics