2012年3月24日星期六

Nike Shoes

,Vibram 5 Fingers Shoes

解解request乱码问题(提交的是中文信息):

    Servlet服务端部分代码:

    public void doPost(httpServletRequest request, httpServletResponse response)

    throws ServletException, IOException{

    //在获取用户表单信息之前把request的码表设置成UTF-8,

    //如果没这句的话,如果提交中文信息的时候,Coach Store,会照成乱码。

    request.setCharacterEncoding("UTF-8");

    String value =request.getParameter("username"); //从request中获取客户端提交过来的信息

    System.out.println(value);

    }

      Servlet服务端部分代码:

      public void doPost(httpServletRequest request,Moncler Sale, httpServletResponse response)

      throws ServletException, IOException{

      //从request中获取客户端提交过来的中文信息,获取到乱码

      String value =request.getParameter("username");

      //拿到乱码反向查找 iso-8859-1 码表,获取原始数据,

      //在构造一个字符串让它去查找UTF-8 码表,已得到正常数据

      value1 =new String (value.getBytes("iso-8859-1"),Nike Shoes, "UTF-8") ;

      System.out.println(value);

      }

        <a href="/Servlet/test?username=江西">登录<a/>

        总结:

        通过get提交表单信息有两种:

        1.通过form表单的 method 设置 get方法提交(即method="get") 默认也是 get

        通过get方法提交到 Servlet程序中, 首先是得到表单的信息,Moncler Store,但是乱码,

        然后还得手动去设置编码方式

        即 value1 =new String (value.getBytes("iso-8859-1"), "UTF-8")

        2.通过超链接提交

        通过post提交表单:

        在form表单的 method 设置 post方法提交(即method="post") ,

        通过post方法提交到 Servlet程序中,request 要在得到表单信息之前 设置编码方式

        即 request.setCharacterEncoding("UTF-8");

        Related articles:

        没有评论:

        发表评论