*.jsp
<%=test.setTest()%>*.java
public void setTest(String newTest) {this.test = newTest;}
JSP提交页面到javaBean会出现汉字乱码怎么解决?
我不想用servlet

解决方案 »

  1.   

    *.jsp 
    <%=test.setTest("成功发表!")%> *.java 
    public   void   setTest(String   newTest)   {this.test   =   newTest;} 
      

  2.   

    在jsp的第二行,加上
    <%request.setCharactorEncoding("GBK"); %>
    或者
    <%request.setCharactorEncoding("UTF-8"); %>根据你采用的编码不同,记得是第二行
    第一行一般是
    <%@page contentType....
      

  3.   

    似乎不行
    *.JSP
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <form action="" method="post" name="form">
              标题:<input type="text" name="title" value="">
              内容:<input type="text" name="content" value="">
              <input type="submit" value="送出" name=submit>
            </form>
            <jsp:useBean id="test" class="javaBean.test" scope="session"></jsp:useBean>
            你输入的是:
            <% 
                String title=request.getParameter("title");
                String content=request.getParameter("content");
                test.setTest(title,content);
             %>
            <%=test.getTest()%>
        </body>
    </html>
    *.javaimport java.io.*;public class test implements java.io.Serializable { 
            
        String Test="";    public String getTest() {return Test;}    public void setTest(String title,String content) {        this.Test = "标题:"+title+"<br>内容:"+content;
        }
    }
      

  4.   

    换成这个试试<%@ page contentType="text/html; charset=GBK" %>
      

  5.   

    <%@ page contentType="text/html; charset=GBK" %>
    <%request.setCharactorEncoding("UTF-8");   %>
    传送数据之前将编码更改过来
      

  6.   

    好了,缺少这个
    <%request.setCharacterEncoding("utf-8");%>
    我以前试着在*.java里加这个
    结果怎么也加不上,原来在这里加
      

  7.   

    <%@page  contentType="text/html";charset="GBK"%><% request.setCharactorEncoding("UTF-8");%>
    <% request.setCharactorEncoding("GBK");%> 
    都可以解决中文乱麻的问题么
      

  8.   

    <%@ page contentType="text/html; charset=UTF-8" %>
    <%request.setCharactorEncoding("UTF-8");%>
    <html> 
            <head> 
                    <meta   http-equiv="Content-Type"   content="text/html;   charset=UTF-8"> 
            </head> 
            <body> 
                    <form   action=""   method="post"   name="form"> 
                        标题: <input   type="text"   name="title"   value=""> 
                        内容: <input   type="text"   name="content"   value=""> 
                        <input   type="submit"   value="送出"   name=submit> 
                    </form> 
                    <jsp:useBean   id="test"   class="javaBean.test"   scope="session"> </jsp:useBean> 
                    你输入的是: 
                    <%   ]
                                            String   title=request.getParameter("title"); 
                            String   content=request.getParameter("content"); 
                            test.setTest(title,content); 
                      %> 
                    <%=test.getTest()%> 
            </body> 
    </html> 
    *.java import   java.io.*; public   class   test   implements   java.io.Serializable   {   
                    
            String   Test="";         public   String   getTest()   {return   Test;}         public   void   setTest(String   title,String   content)   {                 this.Test   =   "标题:"+title+" <br> 内容:"+content; 
            } 
    }
      

  9.   

    建议写个过滤器
    另外,中文乱码网上应该会有一筐好用的方法
    在页头上加上这句:   
      <%@page   contentType="text/html;charset=GB2312"%>     
      在jsp页面上加入这条语句:   
      <%   request.setCharacterEncoding("gb2312");   %>  
    =================================================
    或者
    response.setContentType("text/html;charset=GB2312");   
      request.setCharacterEncoding("gb2312");   
      str=new   String(request.getParmaeter("str").getBytes("ISO-8859_1"),"GB2312");