Get the App
SLTechnology News&Howtos  ›  Development  › 

What about the garbled codes in JSP?

Shulou Source: shulou.com Published: 2022-06-02 12:33:46 11月30日 Update

This article will explain in detail what to do about JSP Chinese garbled code. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. Call the JSP page to display garbled code

When the JSP page is called through the browser, all the Chinese content appears garbled in the client browser.

Resolve:

First make sure that when you save this JSP in the editor, you are using the GBK encoding format, and then add it at the beginning of the JSP page to solve the Chinese garbled problem.

two。 Call the Servlet page to display garbled code

The content displayed in the browser is garbled by calling Servlet,Servlet through the browser.

Resolve:

Before Servlet uses response to output the content, execute response.setContentType ("text/html;charset=GBK") to set the encoding of the output to GBK

Parameters passed by 3.Post form are garbled

Submit parameters to the corresponding JSP page or Servelt through the form elements in the JSP page, HTML page or Servlet, while the Chinese parameter values received by the JSP page or Servlet are garbled.

Resolve:

Before receiving the parameters submitted by POST, use request.setCharacterEncoding ("GBK") to set the contents of the receive parameters using GBK encoding

A better solution is to use filter technology.

Package com.htt; 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 Encoding implements Filter {public void destroy () {} public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {request.setCharacterEncoding ("GBK"); chain.doFilter (request, response) } public void init (FilterConfig filterConfig) throws ServletException {}} Web.xml file settings encoding com.htt.Encoding encoding / ToCh_zn on "JSP Chinese garbled code how to do" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Garbled page content Chinese parameters browser browse article code how to do more form output good practical element client client technology file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Microsoft Linux MySQL