JSP transfer value Chinese garbled problem Solving Method Example Introduction _jsp programming

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:

<%request.setcharacterencoding ("UTF-8");%>
<form action= "" method= "POST" >
Name: <input type= "text" name= "name"/>
<br/>
Sex: <input type= "text" name= "Sex"/>
<%
String name=requset.getparameter ("name");
String sex=request.getparameter ("sex"); Out.print (name);
Out.print (Sex);
%>
</form>

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:

<form action= "" method= "POST" >
User name: <input type= "text" name= "name"/>
<br/>
Password: <input type= "password" name= "password"/>
<form/>
String name=requset.getparameter ("name");
String password=request.getparameter ("password");
Application.setattribute ("names", name);
Application.setattribute ("Passwords", password); Passwords and usernames are so remembered that they can be arbitrarily invoked in others, as follows
Application.getattribute ("names");
Application.getattribute ("passwords");
<%
Out.print (Application.getattribute ("names"));
Out.print (Application.getattribute ("Passwords")
%>

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.