日期:2014-05-17  浏览次数:20762 次

还是乱码问题啊 ???
jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String te=request.getParameter("te");
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
   
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
   <table> <TR><td>我是中文 </td></TR>
   </table><br>-----------<%=te%>
    <form action="Testservlet" method="get">
    <table>
     <tr>
       <td>
         <input name="te" type="text" value=""/>
         <input name="su" type="submit" value="提交"/>
       </td>
     </tr>
    </table>
    </form>
  </body>
  <table>
   <tr>
     <td>
     ___${te}
     </td>
   </tr> 
  </table>
</html>


servlet:

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletExceptionIOException {

PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
// response.setCharacterEncoding("UTF-8");
    String te=request.getParameter("te");
//     te=new String(te.getBytes("ISO-8859-1"),"GBK");
    System.out.println(te+"/////");
request.setAttribute("te",te);
request.getRequestDispatcher("/index.jsp").forward(request, response);
}


但是 jsp还是显示乱码啊?
jsp提交前的:



jsp提交后就乱码了:






------最佳解决方案--------------------
嗯,这问题写过滤器看好使不、

------其他解决方案--------------------
 过滤器 可以实现,    或者 request.setCharacterEncoding("UTF-8");
                          response.setCharacterEncoding("UTF-8"); 放在方法内头两行
------其他解决方案--------------------
       PrintWriter out = response.getWriter();         
request.setCharacterEncoding("UTF-8"); //  response.setCharacterEncoding("UTF-8");         
String te=request.getParameter("te"); //   te=new String(te.getBytes("ISO-8859-1"),"GBK");