JSP programming in the Web page appears garbled, the basic can be grouped into 5 categories:
1. JSP page display garbled.
2. When the servlet receives the parameters passed by Form/request, it is displayed as garbled
3. JSP to receive form/request passed parameters when displayed as garbled
4. <jsp:forward page= "catalog2.html" when the page display garbled
5. Database access to generate garbled.
Here's how to solve all of the following:
Steps/Methods
1. JSP page display garbled.
The first is to add at the beginning of the page:
<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%>
Note: Sometimes if you don't add this sentence at the beginning of the page, you cannot save the Chinese character in the page and prompt: Chinese characters cannot be mapped by the iso-8859-1 character set, which is because by default the JSP is encoded with iso-8859-1 and can be window-> Under the preferences->general->content type option, select text->jsp on the right window, and then change from default Iso-8859-1 to GBK in the following defaults encoding Then click Update to resolve.
This column more highlights: http://www.bianceng.cn/webkf/JSP/
This approach, however, poses some problems: because this sentence cannot be inherited when other files include the file, the file including it also needs to be added to the beginning of the file, and there is a problem with pageencoding= "GBK". Similar to org.apache.jasper.JasperException:/top.jsp (1,1) Page Directive:illegal to have multiple occurrences of ContentType W ith different values (OLD:TEXT/HTML;CHARSET=GBK, NEW:TEXT/HTML;CHARSET=GBK).
Similarly, if two files are GBK and one is gb2312, a problem will arise.
Another way to better solve the problem is to:
Add the following fragment to the project's Web.xml:
<jsp-config>
<jsp-property-group>
<description>
Special Property Group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
<jsp-property-group>
<description>
Special Property Group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GBK</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>
2