为何我的网页中的字体显示乱码呢?

bafnay 2004-09-29 07:45:20
session_login.html代码如下:
<html>
<body>
<form method=post action="check_login.jsp">
<table>
<tr><td>name:</td><td>
<input type=text name=name>
</td></tr><tr><td>password:</td><td>
<input type=text name=password>
</td></tr><tr colspan=2><td>登录类型:
<input type=radio name=type value=manager Checked>管理员
<input type=radio name=type value=user>普通用户
</td></tr>
<tr colspan=2>
<td>
<input type=submit value=login>
</td>
</tr>
</table>
</body>
</html>

check_login.jsp代码如下:
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
String type=request.getParameter("type");
//检查用户登录是否成功,这里假设用户名为hellking就表示登录成功,
//用户的验证通常通过连接数据库或者使用role来进行。
if(name.equals("hellking"))
{
session.setAttribute("name",name);
session.setAttribute("type",type);
response.sendRedirect("loginsucess.jsp");
}
else
{
response.sendRedirect("session_login.html");
}
%>
loginsucess.jsp代码如下:
<br>
<hr>
登录成功。欢迎您!
<%=session.getAttribute("name")%>
<%
if(session.getAttribute("type").equals("manager"))
{
%>
<a href=manage.jsp>进入管理系统</a>
<%
}
else
{
%>
<a href="user.jsp">进入使用界面</a>
<%
}
%>
这是我做试验的代码请帮我看一下错在哪 里啊!不知道为什么在页面上是乱码??






...全文
664 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyong_try 2004-09-29
  • 打赏
  • 举报
回复
我刚才把你的代码测试了一遍
加上<%@ page contentType="text/html;charset=gb2312" %>

在需要传输中文参数的时候请使用
String name=new String(request.getParameter("name").getBytes("ISO8859-1"));

问题是可以解决的,
jzg1234 2004-09-29
  • 打赏
  • 举报
回复
可以看看这个啊
http://blog.csdn.net/kingapex1/articles/93688.aspx
hbuzhang 2004-09-29
  • 打赏
  • 举报
回复
在check_login.jsp里上面也得写上<%@ page contentType="text/html;charset=gb2312" %>
这个是转换本页面的中文问题!
jzg1234 2004-09-29
  • 打赏
  • 举报
回复
网页开始加上
<%@ page contentType="text/html; charset=gb2312"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

要是中文参数要用
<%

String st=new String(request.getParameter("name").getBytes("ISO8859-1"));
%>
hbuzhang 2004-09-29
  • 打赏
  • 举报
回复
只要在check_login.jsp里写上
<%request.setCharacterEncoding("gb2312");%>
就可以了,这个能转换相互请求页面的中文问题。
bafnay 2004-09-29
  • 打赏
  • 举报
回复
我试过了,还是不行!
bp69 2004-09-29
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=gb2312" %>
bp69 2004-09-29
  • 打赏
  • 举报
回复
<......charset=gb2312>

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧