您的位置:首页 > Web前端 > HTML

从一个网页传送表单到别一个网页时的中文处理问题

2006-01-30 19:49 316 查看
第一种方法:

8.jps

<%@page contentType="text/html;charset=gb2312"%>
<html>
 <body>
  <form action="9.jsp">
   <input type="text" name="d1" >
   <input type="submit" value="asd">
  </form>
 </body>
</html>

9.jsp

<%@page contentType="text/html;charset=gb2312"%>

 <%
 String name;
 name=new String(request.getParameter("d1").getBytes("ISO8859-1"),"GBK");
 %>
 <%=name%>

用到name=new String(request.getParameter("d1").getBytes("ISO8859-1"),"GBK");这个解决中文传送的问题。

第二种方法:

可以在本程序内加入以一下java代码函数,再调用就可以了;

<%!
 public String getStr(String str1)
 {
 try
 {
 String temp_p=str1;
 byte[] temp_t=temp_p.getBytes("ISO8859-1");
 String temp=new String(temp_t);
 return temp;
 }
 catch(Exception e)
 {
 }
 return "null";
 }
 %>

这里要用try ...catch捉异常
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息