servlet项目

一、servlet提供的两种跳转页面的方法:

  1、Sendredirect:

  2、forward:

二、httpServletResponse的说明:

  1、getWriter 用于向客户机会送字符数据。

  2、getoutputStream  可以回送字符数据,也可以回送文本数据。

三、中文乱码问题:

  1、表单提交:

    (1)post:

        response.setCharacterEncoding("utf-8");

    (2)get:

        string u=new String(request.getParameter("username").getBytes("iso-8859-1"),"utf-8");

  2、超链接:

    和get方法相同。

  3、sendredirect() 乱码:

    

  说明:尽量用post方式提交。

四、HttpServletResponse应用:

  1、文件下载:

    

  2、生成随机验证码:

    

 五、HttpServletRequest应用:

  1、请求头代表了客户端对服务器的请求(http请求),当web服务器得到该请求后,会把请求的信息封装成HttpSvervletRequest信息。

  2、可以获取的信息:

    

  3、获取表单提交的内容:

    (1)getParameter方法。

    (2)getParametervalues方法:

      用hidden传输:

        可以不破坏页面,提交信息。

    (3)实现请求转发:

        

原文地址:https://www.cnblogs.com/yangsongwei/p/8996133.html