JSP页面要写上  encoding = gbk

解决方案 »

  1.   

    你写上这句request.setCharacterEncoding("gb2312");
    如果你只是写jsp的话就写在jsp页面里,但是要向上写,不要在你要输出的语句下面写。
    如果写MVC模式的话就写在servlet里。肯定好用
      

  2.   

    我的源程序如下,请各位看看:
    <%@ page language="java" %>
    <%@ taglib  uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/cms.tld" prefix="cms" %>
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page import="java.util.Map" %>
    <%@ page import="cms.admin.control.CheckPermission" %>
    <%@ page errorPage="../errorPage.jsp" %><% if (session.getAttribute("user")==null) throw new Exception("session is not loaded,please logon!");  
    CheckPermission cp=new CheckPermission();
    if  (!(cp.isPermission((Integer)(((Map)session.getAttribute("user")).get("user_num")),"editoroptions.do")))
    throw new  Exception("Sorry, you do not have permission to access this page!");
    %><html:html>
    <head>
      <title>search and edit and assign</title></head><script language="JavaScript">
    function toassign(){
    document.all["actionTag"].value ="1";
    document.all["EditAssignAllToTranslateForm"].submit();
    }
    function todel(){
    document.all["actionTag"].value ="2";
    document.all["EditAssignAllToTranslateForm"].submit();
    }
    function toviewassign(){
    document.all["actionTag"].value ="3";
    document.all["EditAssignAllToTranslateForm"].submit();
    }
    </script><BODY>
    <table border="1" width="90%" align="center">
    <tr>

    <logic:iterate id="link" name="linkproductline">  
                  <td><a href="./editallpage.do?product_id=<bean:write name="link" property="product_id"/>"><bean:write name="link" property="product_name"/></td>
    </logic:iterate>
    <td><a href="./editoroptions.do">section page</a></td>
    <td><a href="./options.do">main page</a></td>

    </tr>
    </table>
    <hr>
    <p>You are in <font color="#FF0000"><b><%=(String)request.getAttribute("product_id")%></b></font>line</p>
    <font color="#FF0000"><b><html:errors/></b></font><%if ((String)request.getAttribute("prompt")!=null){%>
    <font color="#FF0000"><b><%=(String)request.getAttribute("prompt")%></b></font>
    <%}%>
    <html:form action="/assignalltotranslate"> 
    <input type="hidden" name="actionTag">
    <input type="hidden" name="product_id" value="<%=(String)request.getAttribute("product_id")%>">
               

               <p> choose a translator:<cms:userListTag name="editUserNum" value="<%=(String)request.getAttribute("usernum")%>" /></p>
             <p>the search result:<%=request.getAttribute("fromend")%></p>
    <p>
    <table border="1" width="100%" id="table1">
    <tr>
    <td>checkSel</td><td>itme_num</td><td width="20%">title</td><td>edit_user</td><td>date_of_entry</td><td>category</td><td>status</td><td>product line</td><td>back to editor reason</td>
    </tr><logic:iterate id="result" name="resulteditsearch">  
    <tr>
    <td><input type="checkbox" name="processed_num" value="<bean:write name="result" property="processed_num"/>"></td>
    <td>
    <a href="./editpage.do?processed_num=<bean:write name='result' property='processed_num'/>"><bean:write name="result" property="processed_num"/></a></td>
    <td width="20%"><a href="./editpage.do?processed_num=<bean:write name='result' property='processed_num'/>"><bean:write name="result" property="subject"/></a></td>
    <td><bean:write name="result" property="user_id"/></td>
    <td><bean:write name="result" property="entry_date"/></td>
    <td><bean:write name="result" property="category"/></td>
    <td><bean:write name="result" property="status_id"/></td>
    <td><bean:write name="result" property="productid"/></td>
    <td><bean:write name="result" property="reason"/></td>

    </tr>
    </logic:iterate></table>
    <p>
    <input type=button value="assign to translator" onclick="toassign();"><input type=button value="delete" onclick="todel();"><input type=button value="view articles assigned to transltor" onclick="toviewassign();">
    </p></html:form>
    </body>
    </html:html>
      

  3.   

    我原先也碰到过在jsp中的中文问题,但其实只用一行代码就可以解决。
    比如要获取另一个页面提交过来的信息。
    String '课程名'= new String(request.getParameter("'课程名'").getBytes("iso-8859-1"));
    你再看一下你想获取的变量,用这个应该可以解决,你试一下。
      

  4.   

    把下面这句
    <html:html>
    改为:
    <html:html local="true">
      

  5.   

    同意: xingfo(一江涛水) 所说
      

  6.   

    在整个站点写一个设置字符编码的Filter
      

  7.   

    你直接写在页面里面的中文不会出现乱码把。是不是只有通过<bean:write name="link" property="product_name"/>
    显示的中文是乱码呢?要是这样,可能是数据库中文乱码。
      

  8.   

    public String GBK(String action)
    {
    try
     {
    if(action==null)
    {
    action ="";
    }
    byte[] b =action.getBytes("ISO8859_1");
    String convert =new String(b,"GBK");
    return convert;
    }
    catch(Exception e)
    {
       System.out.println("GBK Exception:"+e);
    }
    return " ";
    }
      

  9.   

    1.jsp中:写上
    <%@ page contentType="text/html;charset=GB2312" %>2.servlet中从request中取得string时转一下:
    String name=request.getParameter("username");
    name=new String(name.getBytes("ISO8859_1"))3.连接mysql时写成如此:
    jdbc:mysql://192.168.3.235:3306/no2?useUnicode=true&characterEncoding=GB2312
      

  10.   


    1、使用如下命令生成对应的文件 native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties
    2、在JSP文件中做如下设置:
    1、<%@ page language="java" contentType="text/html; charset=utf-8"%>  一定是:utf-8
    2、<html:html locale="true">3、好像在eclipse中不好直接写很多的属性文件,建议打开对应的文件夹后,用记事本工具一个个的写较好。
      

  11.   

    呵呵,看错了。我是用struts实现的
      

  12.   

    如果是要连接到Bean中,觉得像上面的flyingwheat做的转换函数可以实现了。
    如果是在JSP页面中的连接数据库的话,只要把获取的值做一下转换就行了,
    当然,要先写<%@ page contentType="text/html;charset=GB2312" %>
    要是可以在<head></head>中也写上一个<meta>,在其中写上contentType="text/html;charset=GB2312" 这个属性。我想用jsp连接数据库应该没什么问题吧。
      

  13.   

    struts不是有國際化標准嗎?request.setCharacterEncodint("utf-8");
    在servlet 中。