JSP. Use encodingfilter in PetStore

Source: Internet
Author: User

/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* 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 disclawing.
*
*-Redistribution in binary form must reproduce the above Copyright
* Notice, this list of conditions and the following disclawing in
* The documentation and/or other materials provided with
* Distribution.
*
* Neither the name of Sun Microsystems, Inc. Or the names
* 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 particle 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
* 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
* 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: used to set the Request Encoding Method </P>
* <PRE> define the filter in Web. xml. The configuration is 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) throws javax. servlet. servletexception {
This. Config = filterconfig;
This.tar getencoding = config. getinitparameter ("encoding ");
}
Public void dofilter (servletrequest srequest, servletresponse sresponse, filterchain) throws java. Io. ioexception, javax. servlet. servletexception {
Httpservletrequest request = (httpservletrequest) srequest;

// Set the Encoding
Request.setcharacterencoding(this.tar getencoding );

// Move to next
Filterchain. dofilter (srequest, sresponse );
}
Public void destroy (){
This. Config = NULL;
This.tar getencoding = 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.