Solution to java garbled filter
How to deal with Chinese garbled characters using Filter filter in java
Attention: When learning to use selvert filter When filter handles Chinese garbled characters, utf-8 is used to handle Chinese garbled characters when the filter configuration is initialized, but gbk is used in the submitted jsp page. Although both can produce Chinese garbled characters, they result in inconsistent formats for processing garbled characters. So the compilation error occurred.
Recommended tutorial: "java learning"
Solution: Use utf-8 or gbk everywhere
//过滤器类 CharactorFilter.jsp package cn.com.Filter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class CharactorFilter implements Filter { //继承Filter类 //字符编码 String encoding=null; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if(encoding!=null){ //设置request字符编码 request.setCharacterEncoding(encoding); //设置response字符编码 response.setContentType("text/html;charset="+encoding); } //传递给下一个过滤器 chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { //获取初始化参数 encoding=filterConfig.getInitParameter("encoding"); } public void destroy() { // TODO Auto-generated method stub encoding=null; } }
web.xml
<filter> <!--注意这里是filter,不要配置成servlet--> <filter-name>CharactorFilter</filter-name> <!--过滤器名称--> <filter-class>cn.com.Filter.CharactorFilter</filter-class> <!--过滤器的完整类名--> <init-param> <!--初始化参数--> <param-name>encoding</param-name> <!--参数名称--> <param-value>utf-8</param-value> <!--参数值--> </init-param> </filter> <filter-mapping> <!--过滤器映射--> <filter-name>CharactorFilter</filter-name><!--过滤器名称--> <url-pattern>/*</url-pattern><!--URL映射,给所有页面处理乱码--> </filter-mapping>
The above is the detailed content of Solution to java garbled filter. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

TestthePDFinanotherapptodetermineiftheissueiswiththefileorEdge.2.Enablethebuilt-inPDFviewerbyturningoff"AlwaysopenPDFfilesexternally"and"DownloadPDFfiles"inEdgesettings.3.Clearbrowsingdataincludingcookiesandcachedfilestoresolveren

Importjava.ioandjava.net.SocketforI/Oandsocketcommunication.2.CreateaSocketobjecttoconnecttotheserverusinghostnameandport.3.UsePrintWritertosenddataviaoutputstreamandBufferedReadertoreadserverresponsesfrominputstream.4.Usetry-with-resourcestoautomati

Containerized Java application: Create a Dockerfile, use a basic image such as eclipse-temurin:17-jre-alpine, copy the JAR file and define the startup command, build the image through dockerbuild and run locally with dockerrun. 2. Push the image to the container registry: Use dockertag to mark the image and push it to DockerHub and other registries. You must first log in to dockerlogin. 3. Deploy to Kubernetes: Write deployment.yaml to define the Deployment, set the number of replicas, container images and resource restrictions, and write service.yaml to create

In VSCode, you can quickly switch the panel and editing area through shortcut keys. To jump to the left Explorer panel, use Ctrl Shift E (Windows/Linux) or Cmd Shift E (Mac); return to the editing area to use Ctrl ` or Esc or Ctrl 1~9. Compared to mouse operation, keyboard shortcuts are more efficient and do not interrupt the encoding rhythm. Other tips include: Ctrl KCtrl E Focus Search Box, F2 Rename File, Delete File, Enter Open File, Arrow Key Expand/Collapse Folder.

RuntheWindowsUpdateTroubleshooterviaSettings>Update&Security>Troubleshoottoautomaticallyfixcommonissues.2.ResetWindowsUpdatecomponentsbystoppingrelatedservices,renamingtheSoftwareDistributionandCatroot2folders,thenrestartingtheservicestocle

Javaserializationconvertsanobject'sstateintoabytestreamforstorageortransmission,anddeserializationreconstructstheobjectfromthatstream.1.Toenableserialization,aclassmustimplementtheSerializableinterface.2.UseObjectOutputStreamtoserializeanobject,savin

AwhileloopinJavarepeatedlyexecutescodeaslongastheconditionistrue;2.Initializeacontrolvariablebeforetheloop;3.Definetheloopconditionusingabooleanexpression;4.Updatethecontrolvariableinsidethelooptopreventinfinitelooping;5.Useexampleslikeprintingnumber

NumPy is the core library for scientific computing in Python. It is good at handling linear algebra operations and provides efficient ndarray arrays and functions in the numpy.linalg module. 1. Use np.linalg.solve(A,b) to solve the linear equation system Ax=b to obtain the solution vector x; 2. Matrix transposition is implemented through A.T; 3. Matrix multiplication can be used to np.dot(A,B) or A@B; 4. Matrix inverse is calculated by np.linalg.inv(A), and the matrix needs to be reversible; 5. The determinant is given by np.linalg.det(A); 6. The eigenvalue and eigenvector are obtained through np.linalg.eig(A), and the eigenvector has been normalized;
