为什么这里提交以后的中文是乱码呢?,我也设置了编码格式的啊?。
<h1>request内置对象</h1>
用户名:<%=request.getParameter("username") %><br>
密码:<%=request.getParameter("userpassword") %><br>
爱好:<%
String[] favorites=request.getParameterValues("favorite");
for(int i=0;i<favorites.length;i++){
out.println(favorites[i]+" ");
} %>
我的用户名是中文;张三,已提交就是乱码了,我的编码也是utf-8啊,什么原因呢
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h1>request对象</h1>
<%
request.setCharacterEncoding("UTF-8");
%>
姓名:<%=request.getParameter("username") %>这是乱码
<br>
<br>
<br>
<%= new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8")
%>
<br>
爱好:
<%
String res[]=request.getParameterValues("aihao");
for( int i=0;i<res.length;i++)
{
out.println(res[i]);
}
%>
</body>
</html>
我也遇到了相同的问题,楼主解决了没有,赐教
设置TOMCAT为UTF-8了吗?
要设置GET的编码,可以修改server.xml文件中,相应的端口的Connector的属性:URIEncoding="UTF-8",这样,GET方式提交的数据才会被正确解码。
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
在<h1>下面一行加 request.setCharacterEncoding("utf-8");试试