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

Common scenarios of garbled codes in JSP and their Solutions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the "common JSP Chinese garbled scenes and their solutions" related knowledge, in the actual case operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

JSP development application is that Chinese garbled is a common problem. The root cause is that the default character processing code of Web container is ISO-8859-1.

Example 1. When the JSP page is displayed

Chinese garbled-Mulan's words are written in ancient times when the JSP page is displayed.

If life is only like the first sight, what is the autumn wind sad painting fan.

It is easy to change the hearts of the old people, but the old people's hearts are changeable.

In the middle of the night, there was no resentment in the tears.

What a lucky brocade Yilang, more than the wish of the same day.

Running result:

Solution: assign a Chinese character set to it, before adding

Example 2. When passing Chinese parameters on the JSP page

Registration page:

Chinese garbled code-apply for an account when passing Chinese parameters on the JSP page:

Mailbox:

Nickname:

Password:

Gender: men and women introduce themselves in one sentence.

Personal Information Page:

Chinese garbled code-user information when passing Chinese parameters on the JSP page:

Mailbox:

Nickname:

Password:

Gender:

Personal introduction:

Running result:

Solution: modify the personal information page as follows

Chinese garbled code-user information when passing Chinese parameters on the JSP page:

Mailbox:

Nickname:

Password:

Gender:

Personal introduction:

Example 3. When Servlet processes Chinese parameters

Registration page:

Chinese garbled code-apply for an account when passing Chinese parameters on the JSP page:

Mailbox:

Nickname:

Password:

Gender: men and women introduce themselves in one sentence.

UserMsg.java (Servlet)

Package test; importjava.io.IOException; importjava.io.PrintWriter; importjava.io.UnsupportedEncodingException; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; public classUserMsg extends HttpServlet {public void doGet (HttpServletRequestrequest, HttpServletResponse response) {doPost (request, response) } public void doPost (HttpServletRequestrequest, HttpServletResponse response) {try {request.setCharacterEncoding ("gb2312");} catch (UnsupportedEncodingExceptione) {e.printStackTrace ();} PrintWriter out = null; try {out = response.getWriter () } catch (IOException E1) {e1.printStackTrace ();} out.print ("); out.print ("); out.print ("+" user information: "+"); out.print ("

"+" mailbox: "+ request.getParameter (" email ") +"); out.print ("

"+" nickname: "+ request.getParameter (" nickname ") +"); out.print ("

"+" password: "+ request.getParameter (" password ") +"); out.print ("

"+" gender: + request.getParameter ("sex") + "); out.print ("

"+" introduction: "+ request.getParameter (" introduction ") +"); out.print (""); out.print ("");}}

Running result:

Solution: add: in doPost:

Response.setContentType ("text/html; charset=gb2312"); "Common JSP Chinese garbled scenarios and their solutions" are introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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