JSP Chinese garbled common 3 examples and its solution _jsp programming

Source: Internet
Author: User

Common 3 examples and their solutions are as follows

Instance one, when the JSP page is displayed

 
 

Run Result:

Workaround: To specify the Chinese character set,

<%@ page contenttype= "text/html;charset=gb2312"%>

Instance two, when the JSP page passes the Chinese parameter

Registration page:

 <%@ page contenttype= "text/html;charset=gb2312"%>  
 

Personal Information page:

 <%@ page contenttype= "text/html;charset=gb2312"%> 

Run Result:

Workaround: Modify the Personal information page as follows

<%@ page contenttype= "text/html;charset=gb2312"%>  

Example three, when the servlet handles Chinese parameters

Registration page:

 <%@ page contenttype= "text/html;charset=gb2312"%> <%@ page import= "test. Usermsg "%>  
 

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 re 
   Sponse) {doPost (request, response); } public void DoPost (Httpservletrequestrequest, httpservletresponse response) {try {reques 
      T.setcharacterencoding ("gb2312"); 
      catch (Unsupportedencodingexceptione) {e.printstacktrace (); 
      } printwriter out = null; 
      try {out = Response.getwriter (); 
      catch (IOException E1) {e1.printstacktrace (); 
      } out.print (" 

Run Result:

Workaround: Add in Dopost:

Response.setcontenttype ("text/html; charset=gb2312 ");

The above is a few common JSP Chinese garbled examples and solutions, I hope to help you solve the problem of JSP Chinese garbled.

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.