欢迎光临
我们一直在努力

JSP中解决乱码的方法。用PetStore中的EncodingFilter-JSP教程,Jsp/Servlet

建站超值云服务器,限时71元/月

/*

* 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;

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » JSP中解决乱码的方法。用PetStore中的EncodingFilter-JSP教程,Jsp/Servlet
分享到: 更多 (0)

相关推荐

  • 暂无文章