Topic: jsp乱码问题

  Print this page

1.jsp乱码问题 Copy to clipboard
Posted by: andilyliao
Posted on: 2006-02-19 14:36

在第一页jiaos.jsp中
<%
    try
    {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con=DriverManager.getConnection("jdbc:odbc:teacher");
      Statement stm=con.createStatement();
      String sqlf="select * from table1";
      ResultSet rers=stm.executeQuery(sqlf);    
      String ttname;
      while(rers.next())
       {
        ttname=rers.getString("tname");
        out.println("<tr>");
        out.println("<td width='770' height='28' background='images1/back (5).jpg' scope='col' align='center'>");
        out.println("<form action='teacher2.jsp' method='post'>");
        out.println("<input name='lookup' type='submit' value='查看'>");
        out.println("<input name='textnamett' type='hidden' value='" + ttname + "'>");
        out.println("</form>");
        out.println(ttname);
        out.println("</tr>");
        out.println("</td>");
      }
      stm.close();
      con.close();
    }
    catch(Exception e)
    {
    }

     %>
在第二页teacher2.jsp中
<%=request.getParameter("textnamett")%>
读出的textnamett就是乱码了

2.Re:jsp乱码问题 [Re: andilyliao] Copy to clipboard
Posted by: xiaoqiang
Posted on: 2006-02-20 16:36

出现的是什么样的乱码?还有你数据库中tname是什么类型?

3.Re:jsp乱码问题 [Re: andilyliao] Copy to clipboard
Posted by: andilyliao
Posted on: 2006-02-21 20:28

乱码是错字,有时是"??"
tname是char类型的

4.Re:jsp乱码问题 [Re: andilyliao] Copy to clipboard
Posted by: xiaoqiang
Posted on: 2006-02-22 09:02

你数据库中tname是否为乱码?若不是,你在第二个页面中就需要中文转换然后才能正确显示

5.Re:jsp乱码问题 [Re: andilyliao] Copy to clipboard
Posted by: xiaoqiang
Posted on: 2006-02-22 09:08

public String chgStr(String str)
{
  try{
    String temp_p=str;
    byte[] temp_t=temp_p.getBytes("ISO8859-1");
    String temp=new String(temp_t);
    return temp;
  }catch(Exception e){
    return null;
  }
}

String ttname=request.getParameter("textnamett");
ttname=chgStr(ttname);

6.Re:jsp乱码问题 [Re: andilyliao] Copy to clipboard
Posted by: andilyliao
Posted on: 2006-02-22 16:52

太感谢了!!Smile


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923