JSP中文问题,本来不应发到这儿,请斑竹暂时保留!!!(JSP版没有实质性进展的回帖,因JSP属于JAVA请各位朋友帮忙,并请斑竹不要删或转移到JSP版块!!!谢谢了!!!!)
使用tomcat5.5  winxp sp2
我用 dreamweaver 编辑!!
<%@ page contentType="text/html; charset=gb2312" 
language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<form id="form1" name="form1" method="post" action="">
  <label>tom
  <input type="text" name="tom" />
  </label>
  <label>my
  <input type="submit" name="Submit" value="提交" />
  </label>
<% 
  //按课本方法测试!!
  //String aa=request.getParameter("tom");
  //byte[] b=aa.getBytes("ISO-8859-1");
 // aa=new String(b);
  //因有错误,再网上搜了两种办法测试!!
  //第一种
 // String a=request.getParameter("tom");
  //String aa=new String(a.getBytes("ISO8859-1")," GB2312");
  //第二种
  //String aa=request.getParameter("tom");
  //byte[] b=aa.getBytes("ISO8859-1"); 
  //aa=new String(b);  %>
  <%= aa%>
</form>
</body>
</html>错误::::
org.apache.jasper.JasperException: Exception in JSP: /Untitled-1.jsp:2118: <% 
19:   //按课本方法测试!!
20:   String aa=request.getParameter("tom");
21:   byte[] b=aa.getBytes("ISO-8859-1");
22:   aa=new String(b);
23:   //因有错误,再网上搜了两种办法测试!!
24:   //第一种
org.apache.jasper.JasperException: Exception in JSP: /Untitled-1.jsp:2623:   //因有错误,再网上搜了两种办法测试!!
24:   //第一种
25:   String a=request.getParameter("tom");
26:   String aa=new String(a.getBytes("ISO8859-1")," GB2312");
27:   //第二种
28:   //String aa=request.getParameter("tom");
29:   //byte[] b=aa.getBytes("ISO8859-1"); org.apache.jasper.JasperException: Exception in JSP: /Untitled-1.jsp:2926:   //String aa=new String(a.getBytes("ISO8859-1"),"GB2312");
27:   //第二种
28:   String aa=request.getParameter("tom");
29:   byte[] b=aa.getBytes("ISO8859-1"); 
30:   aa=new String(b);
31: 
32:   %>

解决方案 »

  1.   

    20:   String aa=request.getParameter("tom");
    21:   byte[] b=aa.getBytes("ISO-8859-1");
    22:   aa=new String(b,"GBK");//将其转换成gb2312就可以了
    23:   
    24:   //第一种当然你也可以写个filter类,在web.xml指定每次提交表单的时候,都进入这个servlet处理一下
      

  2.   

    我刚进入这个csdn注册,给点分吧- -!
      

  3.   

    还是老样子!!!exception org.apache.jasper.JasperException: Exception in JSP: /Untitled-1.jsp:2118: //aa = request.getParameter("tom");
    19: //if(!aa.equals("")){
    20:  String aa=request.getParameter("tom");
    21:  byte[] b=aa.getBytes("ISO-8859-1");
    22:  aa=new String(b,"GBK");//将其转换成gb2312就可以了
    23:   //按课本方法测试!!
    24:  //String aa=request.getParameter("tom");
      

  4.   

    http://community.csdn.net/Expert/topic/4654/4654726.xml?temp=.2187311
      

  5.   

    String trans(String chi)
        {
            String result = null;
            byte temp [];
            try{
                temp=chi.getBytes("iso-8859-1");
                result = new String(temp);
            }
            catch(java.io.UnsupportedEncodingException e){
                return result;
            }
            return result;
        }
        String trans(Object chi){
            return trans(chi.toString());
        }
    调用时
    String aa=this.trans(request.getParameter("tom"));
      

  6.   

    的确是做出来了,但必须用两个页面,一个是提交页面,一个中文处理页面,请问为什么?????????
     
    用的这个代码,请问为什么要存在两个文件中,我将这东西存在一个文件中就出错误!!!xtaotao(淘淘) ( ) 信誉:100  2006-3-31 19:58:29  得分: 5   
       
    2楼正确,NetBeans4.1+Tomcat5.5.7中通过。<!-- index.jsp -->
    <%@page contentType="text/html"%>
    <%@page pageEncoding="GBK"%><html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=GBK">
            <title>JSP Page</title>
        </head>
        <body>    <h1>JSP Page</h1>
        
        <form method="POST" name="login" action="Check.jsp">
    <p>姓名<input type="text" name="name" size="20"></p>
    <p>密码<input type="text" name="pwd" size="20"></p>
    <p><input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2"></p>
        </form>
        
        </body>
    </html>--------------------------------------
    <!-- Check.jsp -->
    <%@page contentType="text/html"%>
    <%@page pageEncoding="GBK"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=GBK">
            <title>JSP Page</title>
        </head>
        <body>    <h1>REsult</h1>
        <%
          String name =  new String(request.getParameter("name").getBytes("ISO-8859-1"));;
          String pwd  = request.getParameter("pwd");
          out.println(name+","+pwd); //name是中文正常;pwd中文乱码
        %>
        
        </body>
    </html>
      

  7.   

    JSP页面上加这个
    <%@ page contentType="text/html; charset=gb2312" 
    language="java" import="java.sql.*" errorPage="" %>    <%
          String name =  new String(request.getParameter("name").getBytes("ISO-8859-1"), "gb2312");
          out.println(name); //name是中文正常;在Servlet也这样用
        %>
      

  8.   

    在一个JSP文件里也没有问题啊
    <!-- index.jsp -->
    <%@page contentType="text/html"%>
    <%@page pageEncoding="GBK"%><html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=GBK">
            <title>JSP Page</title>
        </head>
        <body>    <h1>JSP Page</h1>
        <% 
           String name = request.getParameter("name");
           String pwd = request.getParameter("pwd");
           if(name!=null)
           {
               name = new String(name.getBytes("ISO-8859-1"));
               out.println(name+","+pwd);
           }
           else
           {
        %>
        <form method="POST" name="login" action="index.jsp">
    <p>姓名<input type="text" name="name" size="20"></p>
    <p>密码<input type="text" name="pwd" size="20"></p>
    <p><input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2"></p>
        </form>
        <%}%>
        </body>
    </html>
      

  9.   

    我的方法跟xtaotao有什么不一样的么?
      

  10.   

    jarod_shen()  你什么时候在?
    我在开个帖子给你加分!!! 
      

  11.   

    总结:
    如果不存在检验request.getParameter的返回值是否为空,就会出现错误!!!!!
    但这是为什么??????