应用过滤器如下:
=============过滤器:EncodingFilter.java=============
package com.jspdev.ch16;import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.FilterConfig;public class EncodingFilter implements Filter
{
    protected FilterConfig filterConfig;
    private String targetEncoding = "gb2312";
    
    public void init(FilterConfig config) throws ServletException
{
        this.filterConfig = config;
        this.targetEncoding = config.getInitParameter("encoding");
    }
    
     public  void doFilter(ServletRequest srequest, ServletResponse  sresponse, FilterChain chain)throws IOException, ServletException
 {
            
HttpServletRequest request = (HttpServletRequest)srequest;
 
request.setCharacterEncoding(targetEncoding);
 
chain.doFilter(srequest,sresponse);  
    }    public void setFilterConfig(final FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}
    
public void destroy()
{
this.filterConfig=null;
}
}
================web.xml配置文件================
<?xml version="1.0" encoding="gb2312"?>
<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 web-app_2_4.xsd"
    version="2.4">    <description>
        Examples for the 'standard' taglib (JSTL)
    </description>    <filter>
     <filter-name>encoding</filter-name> 
     <filter-class>com.jspdev.ch16.EncodingFilter</filter-class>
     <init-param>
             <param-name>encoding</param-name>
             <param-value>gb2312</param-value>
     </init-param>
    </filter>

<filter-mapping> 
       <filter-name>encoding</filter-name> 
       <url-pattern>/*</url-pattern>  
    </filter-mapping>

    <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
    </welcome-file-list>
 
    <taglib>
        <taglib-uri>http://hellking.com/function</taglib-uri>
        <taglib-location>/WEB-INF/functions.tld</taglib-location>
    </taglib>
 
</web-app>
===============JSP应用程序===================
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>表达式语言的使用</title>
</head>
<body>
<%request.setCharacterEncoding("gb2312");%>
姓名:${param.userName}<form action="" method="get" name="form1">
  <input type=text name="userName"><br>
  <input type=submit value=提交>
</form></body>
</html>
=============程序运行结果====================

http://localhost:8080/ch16/request.jsp在文本框输入:江苏省
地址栏的反应:http://localhost:8080/ch16/request.jsp?userName=%BD%AD%CB%D5%CA%A1
页面显示效果:姓名:??????

解决方案 »

  1.   

    晕啊,这个问题就无人能解么?另外如果上面的程序,眼睛看的不爽,可以访问这里:http://www.cnjsp.org/cnjbb/showthread.jsp?forumID=4&rootID=34288&announceID=34288
      

  2.   

    不一定能帮你解决问题,不过很想试试,把你的 /WEB-INF/functions.tld 贴出来看看,你的乱码问题应该出在那里面。
      

  3.   


         try
         {
             temp=chi.getBytes("iso-8859-1");
             result = new String(temp);
         }
         
    把你这段代码的ISO-8859-1也改为gb2312,我试过可以解决,不过我用的是resin+apache,在TOMCAT中不用改
      

  4.   

    上面的2位回答的统统不对,那玩意是表单式语言,用 ljm9412(badistuta) 说的方法根本不好弄的,而问题的解决方法是这样的:将:“<%@ page contentType="text/html; charset=gb2312" language="java"%>”
    改为:<%@ page contentType="text/html" language="java"%> 我发现很多人根本不懂得表达式的使用。谢谢各位!