/*
* copyright 2002 sun microsystems, inc. all rights reserved.
*
* redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* – redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* – redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* neither the name of sun microsystems, inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* this software is provided "as is," without a warranty of any
* kind. all express or implied conditions, representations and
* warranties, including any implied warranty of merchantability,
* fitness for a particular purpose or non-infringement, are hereby
* excluded. sun and its licensors shall not be liable for any damages
* suffered by licensee as a result of using, modifying or
* distributing the software or its derivatives. in no event will sun
* or its licensors be liable for any lost revenue, profit or data, or
* for direct, indirect, special, consequential, incidental or
* punitive damages, however caused and regardless of the theory of
* liability, arising out of the use of or inability to use software,
* even if sun has been advised of the possibility of such damages.
*
* you acknowledge that software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of
* any nuclear facility.
*/
package com.lims.actions.standardline;
/**
* create jstar
* @author petstore
*
*/
import javax.servlet.filterconfig;
import javax.servlet.servletexception;
import javax.servlet.servletrequest;
import javax.servlet.servletresponse;
import javax.servlet.filterchain;
import javax.servlet.http.httpservletrequest;
import java.io.ioexception;
import javax.servlet.filter;
/**
* <p>title: eaf(enterprise application framework)</p>
* <p>description: 用于设定request的编码方式</p>
* <pre>请在web.xml中定义本filter,配置如下:
* <filter>
* <filter-name>encodingfilter</filter-name>
* <display-name>encodingfilter</display-name>
* <description>set the request encoding</description>
* <filter-class>com.netstar.zhuhai.eaf.web.encodingfilter</filter-class>
* <init-param>
* <param-name>encoding</param-name>
* <param-value>utf-8</param-value>
* </init-param>
* </filter>
*
* <filter-mapping>
* <filter-name>encodingfilter</filter-name>
* <url-pattern>/*</url-pattern>
* </filter-mapping>
* </pre>
* @version 1.0
*/
public class encodingfilter implements filter {
private filterconfig config = null;
private string targetencoding = "ascii";
public encodingfilter() {
}
public void init(filterconfig filterconfig) throws javax.servlet.servletexception {
this.config = filterconfig;
this.targetencoding = config.getinitparameter("encoding");
}
public void dofilter(servletrequest srequest, servletresponse sresponse, filterchain filterchain) throws java.io.ioexception, javax.servlet.servletexception {
httpservletrequest request = (httpservletrequest)srequest;
//set the encoding
request.setcharacterencoding(this.targetencoding);
//move to next
filterchain.dofilter(srequest,sresponse);
}
public void destroy() {
this.config = null;
this.targetencoding = null;
}
}
