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

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

路漫漫,長修遠,我們不能沒有錢
隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
數據加載中……

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

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

 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的子類,在這個類中我 調用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)  編輯 收藏 引用 所屬分類: 跨平臺開發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>
            另类av一区二区| 狂野欧美激情性xxxx| 国产欧美综合一区二区三区| 欧美丝袜第一区| 欧美日韩免费一区二区三区| 欧美日韩高清不卡| 欧美日韩一区二区三区免费| 国产精品盗摄久久久| 国产欧美日韩免费| 在线观看亚洲专区| 一本色道久久综合亚洲精品不| 亚洲一区二区三区精品在线| 欧美在线91| 欧美成人自拍| 一区二区三区回区在观看免费视频 | 亚洲一区二区3| 亚洲欧美中文日韩在线| 久久久久久亚洲综合影院红桃| 美女脱光内衣内裤视频久久网站| 欧美久久成人| 国产一区亚洲| 性欧美1819sex性高清| 欧美一区2区视频在线观看| 鲁大师成人一区二区三区| 亚洲级视频在线观看免费1级| 99精品黄色片免费大全| 香蕉亚洲视频| 国产精品xxxav免费视频| 影音先锋日韩精品| 亚洲在线一区二区| 亚洲高清在线精品| 久久精品男女| 亚洲一级在线观看| 免费观看日韩av| 午夜免费日韩视频| 欧美成人综合网站| 在线成人免费观看| 久久精品成人欧美大片古装| 亚洲国产日韩在线一区模特| 久久国产视频网| 国产免费观看久久| 亚洲综合成人在线| 99国产精品国产精品久久 | 欧美精品免费在线| 韩日精品视频一区| 久久成人亚洲| 中文精品视频一区二区在线观看| 欧美成人免费观看| 亚洲国产精品va在线看黑人| 久久精品一本久久99精品| 亚洲视频在线观看免费| 欧美精品麻豆| 日韩亚洲欧美综合| 亚洲欧洲精品一区二区| 欧美好吊妞视频| 日韩一级片网址| 最新成人在线| 欧美激情综合色| 一区二区av| 日韩视频一区二区三区在线播放免费观看 | 欧美日韩国产区一| 日韩午夜视频在线观看| 欧美激情一区在线| 欧美粗暴jizz性欧美20| 亚洲欧洲日本国产| 最新亚洲激情| 国产精品va| 久久av资源网| 久久精品91久久久久久再现| 黑丝一区二区| 欧美高清在线视频| 欧美二区不卡| 亚洲午夜视频在线| 午夜精品视频网站| 伊人精品视频| 亚洲欧洲在线播放| 国产精品qvod| 久久综合九色99| 欧美激情精品久久久久久变态 | 日韩亚洲欧美精品| 一区二区免费看| 国产午夜精品在线| 欧美成人精品高清在线播放| 欧美精品一区二区在线观看| 亚洲欧美中文日韩v在线观看| 蜜桃av一区二区| 欧美精品一区二区高清在线观看| 亚洲一级二级在线| 久久精品视频99| 99热在线精品观看| 午夜精品福利在线观看| 伊人久久成人| 999在线观看精品免费不卡网站| 国产日韩欧美不卡在线| 欧美国产一区二区在线观看| 国产精品高潮呻吟视频| 欧美 日韩 国产一区二区在线视频 | 欧美日韩视频专区在线播放| 欧美一区二区三区在线| 免费在线成人| 久久精品一区二区三区不卡| 欧美精品日韩综合在线| 久久资源在线| 国产美女精品免费电影| 91久久精品国产91久久| 国产亚洲精品久久久久动| 亚洲日韩第九十九页| 韩国av一区| 亚洲在线视频观看| 一区二区三区 在线观看视频| 久久精品国产77777蜜臀| 亚洲午夜高清视频| 欧美护士18xxxxhd| 欧美电影电视剧在线观看| 国产一区二区欧美| 亚洲在线中文字幕| 亚洲午夜小视频| 欧美.www| 欧美.com| 亚洲国产精品成人精品| 久久精品国产欧美亚洲人人爽| 亚洲专区欧美专区| 欧美色另类天堂2015| 亚洲日产国产精品| 一本色道久久综合| 欧美精品一区二区三区在线看午夜| 美女免费视频一区| 激情欧美一区二区| 久久精品夜色噜噜亚洲a∨| 欧美影院视频| 国产精品网站在线观看| 亚洲午夜精品久久久久久app| 亚洲美女中出| 欧美二区在线观看| 亚洲国产日韩欧美综合久久| 在线成人小视频| 久久久蜜桃精品 | 一区二区91| 国产精品99久久久久久久女警| 欧美激情在线有限公司| 亚洲人成网站在线观看播放| 亚洲三级电影全部在线观看高清| 免费成人激情视频| 亚洲激情网站免费观看| 一区二区日韩欧美| 西瓜成人精品人成网站| 欧美一级在线视频| 国产区欧美区日韩区| 久久国产视频网| 欧美国产日韩一二三区| 日韩午夜激情| 国产伦精品一区二区三区视频孕妇| 亚洲一区激情| 久久久久久亚洲精品不卡4k岛国| 国产又爽又黄的激情精品视频| 久久久久国产一区二区| 亚洲国产成人久久综合| 亚洲一级电影| 激情久久久久久久| 欧美精品久久久久久| 亚洲一区二区免费看| 久久亚洲一区二区| 一区二区精品国产| 国产一区二区黄色| 欧美电影免费观看高清完整版| 一区二区精品在线| 嫩模写真一区二区三区三州| 亚洲欧洲综合另类| 国产精品初高中精品久久| 久久不射中文字幕| 99亚洲视频| 欧美成人资源| 香蕉久久a毛片| 亚洲国产美女| 国产精品一级在线| 欧美r片在线| 午夜在线一区| 99国产精品私拍| 欧美α欧美αv大片| 亚洲午夜激情网站| 亚洲国产成人在线视频| 国产精品入口福利| 欧美人与禽性xxxxx杂性| 欧美在线精品免播放器视频| 亚洲免费观看在线观看| 免费精品视频| 久久久久久伊人| 亚洲综合激情| 中文高清一区| 日韩一区二区电影网| 亚洲电影免费| 激情五月综合色婷婷一区二区| 欧美午夜性色大片在线观看| 久久久水蜜桃av免费网站| 亚洲综合清纯丝袜自拍| 99热免费精品| 亚洲人成亚洲人成在线观看 | 在线亚洲免费视频| 亚洲欧洲一区二区三区| 免费成人在线视频网站|