按提交键后乱码问题又出现了!之前添加request.setCharacterEncoding("utf-8");之后是没有的。上一节增加URIEncoding="utf-8"并没有去除按url提交的乱码问题。我将上一节在service.xml文件增加的URIEncoding="utf-8"删除了也没有用。
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>request内置对象</h1>
<% request.setCharacterEncoding("utf-8");
request.setAttribute("password","1234567asdfas");
%>
用户名:<%=request.getParameter("username") %>
爱好:<%
if(request.getParameterValues("favorite")!=null){
String[] favorites=request.getParameterValues("favorite");
for(int i=0;i<favorites.length;i++){
out.println(favorites[i]+" ");
}
}
%>
<br>
密码:<%=request.getAttribute("password")%><br>
请求体的MIME类型:<%=request.getContentType() %><br>
协议类型及版本号:<%=request.getProtocol() %><br>
服务器主机名:<%=request.getServerName() %><br>
服务器端口号:<%=request.getServerPort()%><br>
请求文件的长度:<%=request.getContentLength() %><br>
请求的真实路径:<%=request.getRealPath("request.jsp")%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>快快注册</h1>
<hr>
<form action="request.jsp" name="regFrom" method="get">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>爱好:</td>
<td><input type="checkbox" name="favorite" value="读书">读书
<input type="checkbox" name="favorite" value="看书">看书 <input
type="checkbox" name="favorite" value="写书">写书 <input
type="checkbox" name="favorite" value="抄书">抄书 <input
type="checkbox" name="favorite" value="收书">收书</td>
</tr>
<tr>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
<a href="request.jsp?username=三八佬">测试URL传参数</a>
</html>你提交的方法是get,因为get方法在tomcat中默认使用ISO-8859-1来传输数据,当你的jsp接收到请求后却用utf-8来解码,这样就不可能得到正确的内容,如果配置server.xml确实能够解决这个问题,但是你皮质之后问题没有解决,可能是你配置错误,或者是eclipse没有进行相应的配置导致的,出现中文乱码的情况有多种,多多尝试就能解决