日期:2014-05-20  浏览次数:20767 次

servlet 显示中文问题
大家好!
              我在写了个简单的jsp页面,里面有个提交表单,提交到servlet中显示一下中文,但为什么都是乱码啊?     请给予解决,谢谢!   具体代码如下:

//   jsp
<%@   page   contentType= "text/html;   charset=GBK "   %>
<%
//response.setCharacterEncoding( "gb2312 ");
//request.setCharacterEncoding( "gb2312 ");
%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body>
<form   action= "./servlet1 ">
<table>
<tr>
<td> <input   type= "text "   name= "name "> <input   type= "submit "   value= "sdsdsd "> </td>
</tr>
</table>
</form>
</body>
</html>
----------------------------------------------------
//servlet1的doGet方法

public   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)   throws
                        ServletException,   IOException   {
               
//                 response.setCharacterEncoding( "gb2312 ");
//                 request.setCharacterEncoding( "gb2312 ");

                response.setContentType( "text/html;   charset=GBK ");
                PrintWriter   out   =   response.getWriter();
                String   name   =   new   String(request.getParameter( "name ").getBytes( "ISO-8559-1 "), "gbk ");
                out.println( " <html> ");
                out.println( " <head> <title> Servlet1 </title> </head> ");
                out.println( " <body   bgcolor=\ "#ffffff\ "> ");
                out.println( " <p> "   +   name   +   " </p> ");
                out.println( " </body> ");
                out.println( " </html> ");
                out.close();
        }

我把在论坛里说的方法都用了,怎么还显示乱码呀!   请帮帮忙,解决后保证给分!

------解决方案--------------------
那就结贴吧