Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What about the garbled codes in JSP?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report