When the form is submitted, when the input Chinese parameter is obtained, the browser will appear garbled in Chinese, then add request.setcharacterencoding ("Utf-8") to the JSP file of the form response. The relevant code is as follows:
Attached: The contents of the JSP file submitted by the form:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> testing JSP built-in objects </title>
<body>
<form action= "internalobjresult.jsp" method= "POST" >
uname:<input type= "text" name= "uname " ><br/>
pwd:<input type= "password" name= "pwd " ><br/>
hobbies:<input type= "text" name= "hobby " >
<input type= "text" name= "hobby " ><br/>
submit:<input type= "Submit" name= "Submit "/>
</form>
</body>
The JSP contents of the form response are as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>my JSP ' internalobjresult.jsp ' starting page</title>
<body>
<%request.setcharacterencoding ("Utf-8");//Do not add this sentence, the browser side Chinese will show garbled
String uname=request.getparameter ("uname");
out.println (uname+ "<br>");
enumeration<?> e=request.getparameternames ()//No <?> There will be a warning.
while (e.hasmoreelements ()) {
out.println (e.nextelement () + "<br>");
}
out.println ("All Values:" + "<br>");
string[] s=request.getparametervalues ("hobby");
for (String temp:s) {
out.println (temp+ "<br>");
}
%>
</body>
The solution of JSP Chinese display garbled