青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

路漫漫,長修遠(yuǎn),我們不能沒有錢
隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
數(shù)據(jù)加載中……

java servlet 的字符filter (轉(zhuǎn)載至chinajavaworld.com)

配置字符過濾器,就不用每個中文都轉(zhuǎn)換,filter會自動將符合條件的編碼進(jìn)行自動轉(zhuǎn)換了.呵呵. 一勞永逸

 package filters;
/*
* XP Forum
*
* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.
*
*/

import javax.servlet.
*;
import java.io.IOException;

/**
* <p>Filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:</p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code>ignore</code> initialization parameter. This parameter
* is required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this
* parameter is set to "true".</li>
* </ul>
*
* <p>Although this filter can be used unchanged, it is also easy to
* subclass it and make the <code>selectEncoding()</code> method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the <code>Accept-Language</code>
* and <code>User-Agent</code> headers, or a value stashed in the current
* user's session.</p>
*
* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
*
* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $
*/
public class SetCharacterEncodingFilter
   implements Filter {

// ----------------------------------------------------- Instance Variables

 
/**
  * The default character encoding to set for requests that pass through
  * this filter.
  
*/
 protected String encoding 
= null;

 
/**
  * The filter configuration object we are associated with. If this value
  * is null, this filter instance is not currently configured.
  
*/
 protected FilterConfig filterConfig 
= null;

 
/**
  * Should a character encoding specified by the client be ignored?
  
*/
 protected 
boolean ignore = true;

// --------------------------------------------------------- Public Methods

 
/**
  * Take this filter out of service.
  
*/
 public 
void destroy() {

   
this.encoding = null;
   
this.filterConfig = null;

 }

 
/**
  * Select and set (if specified) the character encoding to be used to
  * interpret request parameters for this request.
  *
  * @param request The servlet request we are processing
  * @param result The servlet response we are creating
  * @param chain The filter chain we are processing
  *
  * @exception IOException if an input/output error occurs
  * @exception ServletException if a servlet error occurs
  
*/
 public 
void doFilter(ServletRequest request, ServletResponse response,
                      FilterChain chain) throws IOException, ServletException {

// Conditionally select and set the character encoding to be used
   if (ignore || (request.getCharacterEncoding() == null)) {
     String encoding 
= selectEncoding(request);
     
if (encoding != null) {
       request.setCharacterEncoding(encoding);
     }
   }

// Pass control on to the next filter
   chain.doFilter(request, response);

 }

 
/**
  * Place this filter into service.
  *
  * @param filterConfig The filter configuration object
  
*/
 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 Methods

 
/**
  * Select an appropriate character encoding to be used, based on the
  * characteristics of the current request and/or filter initialization
  * parameters. If no character encoding should be set, return
  * <code>null</code>.
  * <p>
  * The default implementation unconditionally returns the value configured
  * by the <strong>encoding</strong> initialization parameter for this
  * filter.
  *
  * @param request The servlet request we are processing
  
*/
 protected String selectEncoding(ServletRequest request) {

   
return (this.encoding);

 }

//EOC


web.xml 中的配置:

 <filter>
   
<filter-name>Set Character Encoding</filter-name>
   
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
   
<init-param>
     
<param-name>encoding</param-name>
     
<param-value>GB2312</param-value>
   
</init-param>
   
<init-param>
     
<param-name>ignore</param-name>
     
<param-value>true</param-value>
   
</init-param>
 
</filter> 

 
<filter-mapping>
   
<filter-name>Set Character Encoding</filter-name>
   
<servlet-name>action</servlet-name>
 
</filter-mapping> 

 
<servlet>
   
<servlet-name>action</servlet-name>
   
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
.... 

測試通過.


他的過濾器我試了有問題,這樣就沒有問題了
<filter>
   
<filter-name>EncodingFilter</filter-name>
   
<display-name>EncodingFilter</display-name>
   
<description>no description</description>
   
<filter-class>com.zhaoqi.util.EncodingFilter</filter-class>
   
<init-param>
     
<param-name>encoding</param-name>
     
<param-value>GB2312</param-value>
   
</init-param>
 
</filter>
 
<filter-mapping>
   
<filter-name>EncodingFilter</filter-name>
   
<url-pattern>/*</url-pattern>
 
</filter-mapping>


看 看下面這短代碼,由于struts的每個請求都要由actionservlet處理,所以我自己寫了一個actionservlet的子類,在這個類中我 調(diào)用request.setCharacterEncoding("GB2312");方法,然后在所有的jsp頁面中的字符顯示為GB2312,所有的 問題都解決了,哈哈。大家試試啊
 
import org.apache.struts.action.ActionServlet;
import javax.servlet.http.
*;
public class MainActionServlet extends ActionServlet{
 public MainActionServlet() {
 }
 protected 
void process(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException {
   
/**@todo Override this org.apache.struts.action.ActionServlet method*/
   request.setCharacterEncoding(
"GB2312");
   super.process(request, response);
 }

posted on 2004-10-22 21:52 Khan 閱讀(573) 評論(0)  編輯 收藏 引用 所屬分類: 跨平臺開發(fā)Java

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            激情视频一区二区| 国产综合久久久久久| 欧美精品激情在线| 亚洲美女在线看| 欧美激情视频免费观看| 欧美一区中文字幕| 久久国产精品99国产精| 久久精品一区二区三区中文字幕| 香蕉成人久久| 久久久久久久综合狠狠综合| 久久久久久噜噜噜久久久精品| 久久爱另类一区二区小说| 欧美综合77777色婷婷| 亚洲欧美不卡| 久久久精品tv| 欧美激情精品久久久久久变态| 欧美电影在线免费观看网站| 亚洲国产欧美一区| 欧美国内亚洲| 一区二区三区视频观看| 亚洲欧美国产另类| 美女视频黄免费的久久| 欧美伦理一区二区| 国产精品自拍一区| 亚洲经典自拍| 亚洲午夜视频在线| 欧美在线观看你懂的| 免费国产自线拍一欧美视频| 欧美激情91| 亚洲曰本av电影| 久久中文字幕一区| 国产精品热久久久久夜色精品三区| 国产伦精品一区二区三区高清版| 在线看无码的免费网站| 日韩视频在线观看免费| 性久久久久久久久久久久| 欧美激情小视频| 亚洲欧美国产制服动漫| 久久精品水蜜桃av综合天堂| 女主播福利一区| 国产伦精品一区二区三区免费迷| 亚洲精品久久在线| 久久精品人人做人人爽| 亚洲精品久久视频| 久久久噜噜噜久久| 欧美日韩一区二区视频在线 | 欧美午夜电影网| 国内精品久久久久久影视8| 亚洲精品一区在线观看| 久久久亚洲欧洲日产国码αv | 国产精品激情偷乱一区二区∴| 激情文学一区| 久久九九全国免费精品观看| 99伊人成综合| 欧美精品久久久久久| 中文av字幕一区| 欧美黄网免费在线观看| 国产精品高清一区二区三区| 亚洲国产成人精品久久久国产成人一区 | 欧美成人一区二区| 国产一区二区三区的电影| 亚洲视频一区二区| 亚洲精品欧美激情| 美女在线一区二区| 亚洲国产精品视频一区| 久久中文在线| 久久久青草婷婷精品综合日韩| 国产欧美 在线欧美| 亚洲男人的天堂在线aⅴ视频| 91久久国产综合久久91精品网站| 久久国产日韩欧美| 激情久久久久久久| 久久夜色精品国产亚洲aⅴ| 欧美一区二区三区在线免费观看 | 亚洲精品中文在线| 欧美激情精品| 免费在线亚洲欧美| 亚洲精品日本| 亚洲精品孕妇| 国产精品草草| 亚洲伊人伊色伊影伊综合网 | 欧美人在线观看| 亚洲无限乱码一二三四麻| 亚洲人体影院| 国产精品成人v| 午夜视频一区在线观看| 亚洲欧美日韩精品在线| 国产一区二区无遮挡| 母乳一区在线观看| 欧美成人精品一区二区| 一本色道久久综合亚洲精品高清 | 在线中文字幕日韩| 一区二区三区久久精品| 国产精品女主播| 久久欧美中文字幕| 欧美成人免费va影院高清| 一区二区三区不卡视频在线观看 | 欧美日韩国产二区| 亚洲香蕉成视频在线观看| 中文亚洲免费| 一区二区在线观看av| 亚洲高清精品中出| 国产精品第十页| 久久久国际精品| 欧美日韩91| 久久久蜜桃精品| 在线成人www免费观看视频| 久久精品一区中文字幕| 久久婷婷成人综合色| 日韩视频一区二区三区在线播放免费观看| 亚洲人成久久| 国产亚洲一区精品| 亚洲精品美女久久久久| 国产毛片一区| 亚洲国产精品久久久久| 国产欧美一区二区三区另类精品| 久久夜精品va视频免费观看| 欧美日韩国产另类不卡| 久久精品电影| 欧美精品在线免费| 久久这里只有精品视频首页| 欧美精品免费在线| 久久欧美肥婆一二区| 欧美午夜免费影院| 亚洲第一毛片| 狠狠色综合日日| 这里是久久伊人| 亚洲免费黄色| 久久国产精品免费一区| 亚洲综合大片69999| 免费一级欧美片在线播放| 欧美一区二区免费视频| 欧美裸体一区二区三区| 欧美成人精品不卡视频在线观看| 国产麻豆9l精品三级站| 亚洲精选91| 亚洲黑丝在线| 久久综合久久综合九色| 久久国产综合精品| 国产精品视频网站| 日韩一区二区精品葵司在线| 亚洲欧洲一区二区在线观看| 久久久九九九九| 久久精品中文字幕免费mv| 国产精品久久999| 99视频在线观看一区三区| 亚洲精品黄网在线观看| 久久久久在线| 麻豆乱码国产一区二区三区| 国产色婷婷国产综合在线理论片a| 亚洲欧洲精品成人久久奇米网| 亚洲国产精品成人综合色在线婷婷| 久久国产视频网站| 久久美女性网| 黄色成人91| 久久在线免费观看视频| 欧美xxx成人| 亚洲狠狠丁香婷婷综合久久久| 久久久久www| 久久影院午夜片一区| 激情成人中文字幕| 久久久天天操| 亚洲福利在线看| 亚洲免费观看高清在线观看 | 亚洲在线视频| 久久精品国产成人| 激情久久五月天| 免费成人高清| 亚洲精品影院在线观看| 亚洲欧美日本日韩| 亚洲精品一区二区网址| 香蕉尹人综合在线观看| 欧美无乱码久久久免费午夜一区| 91久久久久久久久| 亚洲在线电影| 国产欧美日韩在线播放| 欧美在线免费一级片| 免费在线观看成人av| 亚洲人www| 欧美午夜精彩| 亚洲欧美精品在线| 久久精品国产999大香线蕉| 在线视频国产日韩| 男女视频一区二区| 一本色道久久加勒比88综合| 亚洲欧美日韩在线一区| 国产原创一区二区| 欧美精品一区二区三区很污很色的 | 国产日韩欧美成人| 久热精品视频在线| 一本色道久久88精品综合| 久久精品亚洲精品| 亚洲精品免费一二三区| 国产精品手机视频| 免费亚洲视频| 亚洲综合色激情五月| 欧美国产视频在线| 欧美在线1区| 99亚洲一区二区| 国产最新精品精品你懂的|