我在dreamware cs5中编写jsp遇到了乱码问题,很难受。经过查阅资料。终于解决了一些,再次举例,想能帮助更多的人。
例:
<%@ page contentType="text/html; charset=gb2312" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>基本信息填写</title>
</head>
<body bgcolor="#CCCCCC" ><FONT size = 4>
<Form action="receive.jsp" method = post name = form>
<Table border = 1>
<br>姓名:<input type = "text" name = "name" value = ""></br>
<br>性别:<input type ="radio" name = "R" value ="男" checked="default">男
<input type="radio" name = "R" value = "女" >女</br>
<br>联系方式:<input type="text" name="contion" value=""></br>
<br>留下你奋斗的誓言:</br><br><TextArea name="留言" rows="5"
cols="48"></textarea></br>
<br>确认好了吗?欢迎你的加入</br><font face="Arial Black, Gadget, sans-
serif, monospace"></font>
<tr>
<td><input type="submit" name = "submint" value="提
交"></td><span> </span>
<td><input type ="Reset" name = " reset" value="重置"></td>
</tr>
</body>
</html><font face="Times New Roman, Times, serif"><font face="Lucida Console,
Monaco, monospace"></font></font>
例:
<%@ page contentType="text/html; charset=utf-8" %>
<HTML> <body bgcolor="#CC9966">
<head>
<title>您所填写的信息如下</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<br>您的姓名是:
<% String s1 = new String(request.getParameter("name").getBytes("ISO8859-1"),"GBK");
%>
<%=s1%>
<br>性别:
<%String s2 =new String(request.getParameter("R").getBytes("ISO8859-1"),"gbk");
%>
<%=s2 %>
<br>联系方式:
<% String s3 = request.getParameter("contion"); %>
<%= s3 %>
<br>最粗的留言:
<% String s4= request.getParameter("留言");
%>
<%= s4 %>
<p>忠心的谢谢您的关注,很快联系你</p>
</body>
</html>
个人总结:jsp 程序在静态,并没有提交页面时,页面使用gb2312编码
进行了提交操作后,页面采用utf-8 编码,这样可以避免乱码。亲测。可行。希望不要嫌麻烦,,,,,哈哈
注意:上面的代码有个问题,对文本写区的提交存在问题,可是不影响乱码的处理,希望大家帮忙解决

本文分享了在Dreamware CS5中使用JSP遇到的乱码问题及解决方案,通过调整编码设置,在提交前后分别采用gb2312和utf-8编码,有效解决了中文乱码。
601

被折叠的 条评论
为什么被折叠?



