suchen

Heim  >  Fragen und Antworten  >  Hauptteil

java - servlet中,用浏览器打印HTTP表单,出现乱码的问题,下面是相关的代码

用chrome 和 IE都试过(也把编码换成 UTF-8),网址输入为 :
http://localhost:8080/mydoodling/info?username=张
动态生成的网页内容为: 你好寮?
请问中文代码到底是哪个?
获取浏览器表单参数的代码为:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<code>public class ServletInfo extends HttpServlet       

{

        public void doGet ( HttpServletRequest req , HttpServletResponse resp) throws IOException

        {

                String username = req . getParameter ( "username") ;

                if (null != username)

                {

                        username = new String ( username.getBytes ( "ISO-8859-1")  , "GB2312") ;

                }

                resp . setContentType ( "text/html;charset=GB2312") ;

                PrintWriter out = resp . getWriter ( ) ;

                out . println ("<html><body>"+"你好" + username+"</body></html>") ;

                out . close ( ) ;

        }               

}</code>

巴扎黑巴扎黑2889 Tage vor288

Antworte allen(3)Ich werde antworten

  • PHP中文网

    PHP中文网2017-04-17 17:50:05

    1. 检查request.setCharacterEncoding()设置或者是过滤器中字符编码过滤器,保持解码格式跟设置的编码格式一致

    2. 对于GET请求Tomcat会使用ISO-8859-1编码之后使用UTF-8编码

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-17 17:50:05

    查看一下jsp页面上的字符编码

    Antwort
    0
  • PHPz

    PHPz2017-04-17 17:50:05

    典型的url中文乱码啊,以下择一用之。
    1.tomcat的配置文件server.xml中<Connector>标签里加上 URIEncoding="UTF-8“
    2.方法第一行增加request.setCharacterEncoding(“UTF-8”)

    Antwort
    0
  • StornierenAntwort