I encountered the jsp pass parameter garbled situation (Project Unified code UTF-8)

Source: Internet
Author: User

Today really spent a lot of time on this garbled problem Ah! To prevent the next time you or others encounter similar problems to waste too much energy here ...

Close-up some of the unified coding related steps, not often write articles, this article may not write well, for reference only, thank you

The encoding format for the unified files is UTF-8:

My JSP file header: <%@ page language= "java" pageencoding= "UTF-8"%>

(The header of the XML file is the default: <?xml version= "1.0" encoding= "UTF-8"?>)

And through MyEclipse configuration jsp file, JS file default file Encoding format is: UTF-8, (click on MyEclipse toolbar window->>preferences->>general->> Content Types) after

As below, look for the relevant settings on the right side of the window:

such as the bottom of the red circle: Default Encoding:utf-8, finally click OK, complete the setup.

After these settings, check the encoding of the entire project, select your MyEclipse item, right-click the list, select Properties (usually at the end of the list), if the default inherited from container is not UTF-8, then

Click the Other radio button below it, then select UTF-8:

When you create the database, the setting is encoded as UTF-8:

  CREATE DATABASE ' test2 ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

The URL also needs to be set as a unified encoding when connecting to the MySQL database: jdbc:mysql://localhost:3306/db_myname?characterencoding=utf-8

To do this above, has achieved the unification of UTF-8 code! If the Chinese data you stored in the database does not appear garbled,

The following content will not need to read ...

If the database insert Chinese insert is garbled, you may be as careless as I have overlooked the small details:

The above basically has been the whole project code is unified, but I found that I deposited in the database of Chinese data or garbled;

I in the Java implementation of the DAO layer method there directly using "Chinese data" stored in the database, found no garbled, then the MySQL data inventory in Chinese no problem;

That should be a problem with JSP parameter passing,

After that, I use the JavaScript alert () method, pop up the relevant Chinese data, also can display normally;

Finally, many attempts have not found exactly where the problem!

Until I see this:<form action= "Myaction_save" >

Do you see the problem? Here is less: Method property, when not written, the default method= "get", which is not supported in Chinese pass!

We need to be sure to add method= "post", such as: <form action= "Myaction_save" method= "post";

This is a detail that needs attention!

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.