按提交键后乱码问题又出现了!之前添加request.setCharacterEncoding("utf-8");之后是没有的。上一节增加URIEncoding="utf-8"并没有去除按url提交的乱码问题。我将上一节在service.xml文件增加的URIEncoding="utf-8"删除了也没有用。
按提交键后乱码问题又出现了!之前添加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>