JSP to solve the method of garbled. Using the Encodingfilter in Petstore

Source: Internet
Author: User
Tags filter config
js| Resolution/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* Modification, are permitted provided that 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 materials provided with the
* Distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* Contributors May is 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 is liable for any damages
* Suffered by Licensee as A result of USING, modifying OR
* Distributing the SOFTWARE OR its derivatives. In NO EVENT would SUN
* OR its licensors to be liable to 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 ' OR inability to-use SOFTWARE,
* Even IF SUN has BEEN advised of the possibility of SUCH damages.
*
* You acknowledge that Software are 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;

/**
* &LT;P&GT;TITLE:EAF (Enterprise application Framework) </p>
* <p>description: The encoding method used to set request </p>
* <pre> Please define this filter in Web.xml, configured as follows:
* <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;
}

}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.