jsp中用javabean读取值出现乱码
javabean中代码:packagejv;publicclassjavabean{privateStringnme;publicjavabean(){nme=null;...
javabean中代码:
package jv;
public class javabean { private String nme;
public javabean()
{
nme=null;
}
public String getNme() {
return nme;
}
public void setNme(String nme) {
this.nme = nme;
}
private String xh;
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
}
第一个页面代码:
<%@ 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">
<jsp:useBean id="na" scope="session" class="jv.javabean"/>
<jsp:setProperty name="na" property="*" />
<%
if(request.getParameter("nme")!= null )
{
response.sendRedirect("j2.jsp");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action=j1.jsp>
姓名:<input type="text" name="nme"><br>
学好;<input type="text" name="xh"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
接收页面代码:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<jsp:useBean id="na" scope="session" class="jv.javabean"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
request.setCharacterEncoding("utf-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>dd</title>
</head>
<body>
<%= request.getParameter("nme")%>
uucdeeee<%= request.getParameter("xh")%>姓名是:<input type="text" value="<%=na.getNme() %>">
学好是:<jsp:getProperty name="na" property="xh" />
</body>
</html>
输入汉字就是乱码,,输入数字和字母就没有问题!!求高手解答啊 展开
package jv;
public class javabean { private String nme;
public javabean()
{
nme=null;
}
public String getNme() {
return nme;
}
public void setNme(String nme) {
this.nme = nme;
}
private String xh;
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
}
第一个页面代码:
<%@ 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">
<jsp:useBean id="na" scope="session" class="jv.javabean"/>
<jsp:setProperty name="na" property="*" />
<%
if(request.getParameter("nme")!= null )
{
response.sendRedirect("j2.jsp");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action=j1.jsp>
姓名:<input type="text" name="nme"><br>
学好;<input type="text" name="xh"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
接收页面代码:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<jsp:useBean id="na" scope="session" class="jv.javabean"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
request.setCharacterEncoding("utf-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>dd</title>
</head>
<body>
<%= request.getParameter("nme")%>
uucdeeee<%= request.getParameter("xh")%>姓名是:<input type="text" value="<%=na.getNme() %>">
学好是:<jsp:getProperty name="na" property="xh" />
</body>
</html>
输入汉字就是乱码,,输入数字和字母就没有问题!!求高手解答啊 展开
展开全部
在form表单中添加accept-charset="gbk"试试
在<META http-equiv="content-Type" content="text/html;charset=gbk"
在<META http-equiv="content-Type" content="text/html;charset=gbk"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
tomcat配置文件中设置编码,具体百度
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
new String(req.getBytes("ISO8859_1"),"UTF-8");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
getParameter后做一次编码转换,例如:new String(req.getBytes("ISO8859_1"))。其中req是接收到的参数
追问
这样做了啊还是是乱码啊,,
追答
("ISO8859_1")这个是编码方式,试一下其他的编码,例如"GBK"等...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询