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

              *该对象被用作包装位于特定路径上的服务器资源或通过特定名称给定的服务器资源的包装器.

              *该路径名必须以 "/" 开头,并相对于当前上下文根进行解释。

              *如果 ServletContext无法返回RequestDispatcher,则此方法返回 null
              */
    if (dispatcher != null) {
                        dispatcher.include(request, response);
                /*
                 *
    利用include()方法将HTTP请求转送给其他Servlet(/response)后,
                 *被调用的Servlet虽然可以处理这个HTTP请求,但是最后的主导权仍然是在当前的Servlet。
                */
    } }
    @WebServlet("/response")//url映射
    public class ResponseServlet extends HttpServlet {
    
        @Override//重写doGet方法
        public void doGet(HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException, IOException {//抛出可能出现servlet和IO异常
            try (PrintWriter out = response.getWriter()) {//捕获可能发生的异常
    
                // then write the data of the response
                String username = request.getParameter("username");在请求中取得username参数的值
                if (username != null && username.length()> 0) {
                    out.println("<h2>Hello, " + username + "!</h2>");//在前段页面打印username值
                }
            }
        }
  • 相关阅读:
    mysql 索引
    私有变量 _变量名 、__变量名、__变量名__的区别
    python中 is 和 == 的区别
    赋值,浅拷贝,深拷贝
    Django model字段类型清单
    (转)nginx uwsgi wsgi django 这些东西究竟是什么关系
    线性结构
    复杂度_最大子列和问题(2)
    复杂度_最大子列和问题(1)
    应用实例——最大子列和问题
  • 原文地址:https://www.cnblogs.com/bbeb/p/10575053.html
Copyright © 2011-2022 走看看