A sample description of the solution to the Chinese garbled problem of JSP transfer value

Source: Internet
Author: User

In JSP, we often read data from the database back to the client, but we often in the production of garbled phenomenon, so we can use <%request.setcharacterencoding ("UTF-8");%> this method to ensure the correct output of Chinese, Here's an example,
Before we catch the value of the form or print out the database data, put the <%request.setcharacterencoding ("UTF-8");%> in front of them, and then the form must be submitted by post, that is, method= " Post ", so you can close to avoid garbled, please see below:

Copy Code code as follows:


&lt;%request.setcharacterencoding ("UTF-8");%&gt;


&lt;form action= "" method= "post" &gt;


Name: &lt;input type= "text" name= "name"/&gt;


&lt;br/&gt;


Sex: &lt;input type= "text" name= "Sex"/&gt;


&lt;%


String name=requset.getparameter ("name");


String sex=request.getparameter ("sex"); Out.print (name);


out.print (Sex);


%&gt;


&lt;/form&gt;


Or sometimes when the user login, we need to use a user name or password on a page, we can use the following method to remember, in other pages can be arbitrarily called, such as:

Copy Code code as follows:


&lt;form action= "" method= "post" &gt;


User name: &lt;input type= "text" name= "name"/&gt;


&lt;br/&gt;


Password: &lt;input type= "password" name= "password"/&gt;


&lt;form/&gt;


String name=requset.getparameter ("name");


String password=request.getparameter ("password");


Application.setattribute ("names", name);


application.setattribute ("Passwords", password); Passwords and user names are remembered in this way, and can be easily invoked in others, as follows


Application.getattribute ("names");


application.getattribute ("passwords");


&lt;%


Out.print (Application.getattribute ("names"));


Out.print (Application.getattribute ("Passwords")


%&gt;


This will output the value of the text box

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.