JSP Chinese garbled Solution

Source: Internet
Author: User
Test. jsp:

<% @ Page contenttype = "text/html; charset = UTF-8" %>

<HTML>

<Head>

<Title> test </title>

</Head>

<Body>

<H1> test
<A href = "test1.jsp? Username = <% = java.net. urlencoder. encode ("") %> "> Wang Tianji </a>

<Form method = "Post" Action = "test1.jsp" name = "form1">

<Input type = "text" name = "username">

<Input type = "Submit" name = "submit1" value = "click">

</Form>

</Body>

</Html>

Test1.jsp:

");

Byte [] AA = username. getbytes ("ISO-8859-1 ");

String BB = new string (AA, "UTF-8 ");

Out. println ("after:" + BB );

%> <% @ Page contenttype = "text/html; charset = UTF-8" %>

<HTML>

<Head>

<Title>

Test1

</Title>

</Head>

<Body bgcolor = "# ffffff">

<%

String username = "";

Username = request. getparameter ("username ");

Out. println ("before:" + username + "<br> ");

Byte [] AA = username. getbytes ("ISO-8859-1 ");

1. If you want to upload Chinese characters in the address bar, the application is as follows:

String BB = new string (AA );

2. If the form is submitted, the application is as follows:

String BB = new string (AA, "UTF-8 ");

Out. println ("after:" + BB );

%>

</Body>

</Html>

");

Byte [] AA = username. getbytes ("ISO-8859-1 ");

String BB = new string (AA, "UTF-8 ");

Out. println ("after:" + BB );

%> ");

Byte [] AA = username. getbytes ("ISO-8859-1 ");

String BB = new string (AA, "UTF-8 ");

Out. println ("after:" + BB );

%> ");

Byte [] AA = username. getbytes ("ISO-8859-1 ");

String BB = new string (AA, "UTF-8 ");

Out. println ("after:" + BB );

%>

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.