zoukankan      html  css  js  c++  java
  • hello2源代码解析

    String username = request.getParameter("username");
    /*
    *以 String 形式返回请求参数"username"的值,并赋值给username,如果该参数不存在,则返回 null。
    *请求参数是与请求一起发送的额外信息。
    *对于 HTTP servlet,参数包含在查询字符串或发送的表单数据中。
    */
    if (username != null && username.length()> 0) {//若username不为null并且长度大于零则
    RequestDispatcher dispatcher =
    getServletContext().getRequestDispatcher("/response");
              /*
               *定义接收来自客户端的请求并将它们发送到服务器上的任何资源的对象dispatcher
               *该对象被用作包装位于特定路径上的服务器资源或通过特定名称给定的服务器资源的包装器。
              */
              

    if (dispatcher != null) {
    dispatcher.include(request, response);
    }
    }

    @WebServlet("/response")
    public class ResponseServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    try (PrintWriter out = response.getWriter()) {

    // then write the data of the response
    String username = request.getParameter("username");
    if (username != null && username.length()> 0) {
    out.println("<h2>Hello, " + username + "!</h2>");
    }
    }
    }

  • 相关阅读:
    docker学习之路-nginx镜像(翻译)
    docker学习之路-centos下安装docker
    Angular复习笔记7-路由(下)
    Linux保证运行一个实例
    使用epoll实现简单的服务器
    vmware中centos、redhat桥接网络配置
    同步队列、线程池模式服务器消息处理类
    ocilib linux编译安装
    redhat6.5安装oracle11_2R
    redhat6.5安装yum
  • 原文地址:https://www.cnblogs.com/zynn/p/10576846.html
Copyright © 2011-2022 走看看