jsp 在提交内容后的出现乱码 解决

来源:互联网 发布:济南软件外包服务 编辑:程序博客网 时间:2024/05/22 00:34

           我在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>&nbsp;&nbsp;&nbsp;</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 编码,这样可以避免乱码。亲测。可行。希望不要嫌麻烦,,,,,哈哈


注意:上面的代码有个问题,对文本写区的提交存在问题,可是不影响乱码的处理,希望大家帮忙解决

0 0
原创粉丝点击