zoukankan      html  css  js  c++  java
  • servlet_5

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {



    /*请求报文的结构:
    * 【1】:请求首行
    * 【2】:请求头
    * 【3】:空行
    * 【4】:请求体
    *
    * HttpServletRequest
    * 代表:浏览器发送给服务器的请求报文
    * 获取:该对象由Tommat服务器创建,最终作为参数传递到doGet或doPost方法中
    * 功能:
    * 【1】:获取请求参数
    * 【2】:可以获取项目名
    * 【3】:可以作为一个域对象在不同的web资源之间共享数据(request servletContext)
    * 【4】:可以做请求的转发
    *
    *
    *
    *
    *
    *
    */
    //获取请求参数
    /*String username = request.getParameter("username");
    String password = request.getParameter("password");
    //在页面中输出用户名
    response.getWriter().print("<h1>username="+username+"</h1>");
    System.out.println(password);
    //获取项目名
    //主要用来获取绝对路径
    String contextPath = request.getContextPath();
    System.out.println(contextPath);

    /*请求的转发
    *
    * 所谓的转发就是指收到浏览器发送的请求以后
    * 当前servlet不去处理请求
    * 而是去调用服务器内部的资源去处理请求
    * 转发的特点:
    * 【1】转发时浏览器发送了1次请求
    * 【2】转发是在服务器内部进行的
    * 【3】浏览器的地址栏不会发生改变
    * 【4】浏览器不知道转发的发生
    *
    *
    */
    //1.获取一个请求的派发器*/

    RequestDispatcher dispatcher = request.getRequestDispatcher("target.html");
    dispatcher.forward(request, response);

    }

  • 相关阅读:
    【原】【Git】EGit强制覆盖本地文件
    【EGit】The current branch is not configured for pull No value for key branch.master.merge found in config
    【转】【Egit】如何将eclipse中的项目上传至Git
    参加SAP VT项目有感
    2013_12_30 纪念
    2013 12 25 圣诞日
    gin系列-中间件
    gin系列- 路由及路由组
    gin系列-重定向
    gin系列-文件上传
  • 原文地址:https://www.cnblogs.com/fanzhengzheng/p/7572149.html
Copyright © 2011-2022 走看看