首先,我们先来看一看这一段的整体代码,

代码如下:

@WebServlet("/greeting")
public class GreetingServlet extends HttpServlet { @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
response.setBufferSize(8192);
try (PrintWriter out = response.getWriter()) {
out.println("<html lang=\"en\">"
+ "<head><title>Servlet Hello</title></head>"); // then write the data of the response
out.println("<body bgcolor=\"#ffffff\">"
+ "<img src=\"duke.waving.gif\" "
+ "alt=\"Duke waving his hand\">"
+ "<form method=\"get\">"
+ "<h2>Hello, my name is Duke. What's yours?</h2>"
+ "<input title=\"My name is: \"type=\"text\" "
+ "name=\"username\" size=\"25\">"
+ "<p></p>"
+ "<input type=\"submit\" value=\"Submit\">"
+ "<input type=\"reset\" value=\"Reset\">"
+ "</form>"); String username = request.getParameter("username");
if (username != null && username.length()> 0) {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response"); if (dispatcher != null) {
dispatcher.include(request, response);
}
}
out.println("</body></html>");
}
}

对里面的部分代码分析:

String username = request.getParameter("username");  //获取通过URL或者form传递过来的数据并赋值给username
if (username != null && username.length() > 0) {    //对数据进行验证,满足不为空和长度大于0的条件
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");    
 //获取jsp上下文里边存储了各变量的信息(值),把一个命令发送到浏览器,让浏览器对指定的URL提出请求(此处的URL只能使用绝对路径)
if (dispatcher != null) {
dispatcher.include(request, response);    //如果接收到的客户端的请求不为空时,记录保留request和response,以后不能再修改response里表示状态的信息。 
}
}

hello2 source anaylis的更多相关文章

  1. Hello2 source analysis

    在example目录下的web\servlet\hello2\src\main\java\javaeetutorial\hello2路径里可以找到hello2的GreetingServlet.java ...

  2. hello2 Source Analisis

    hello2应用程序是一个web模块,它使用Java Servlet技术来显示问候和响应.此应用程序的源代码位于 _tut-install_/examples/web/servlet/hello2/目 ...

  3. hello2 source analisis(notes)

    该hello2应用程序是一个Web模块,它使用Java Servlet技术来显示问候语和响应.使用文本编辑器查看应用程序文件,也可以使用NetBeans IDE. 此应用程序的源代码位于 _tut-i ...

  4. Analysis of Hello2 source code

    Hello2 应用程序是一个 Web 模块,它使用 Java Servlet 技术来显示问候语和响应,使用的是 Java Servlet 技术. 该应用程序源代码在 tutorial-examples ...

  5. Analisis of Hello2 source

    GreetingServlet.java @WebServlet("/greeting") //为servelt指定URL pattern为:/greeting public cl ...

  6. seL4之hello-2旅途(完成更新)

    seL4之hello-2旅途 2016/11/19 13:15:38 If you like my blog, please buy me a cup of coffee. 回顾上周 seL4运行环境 ...

  7. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...

  8. mysql-5.6.34 Installation from Source code

    Took me a while to suffer from the first successful souce code installation of mysql-5.6.34. Just pu ...

  9. source /etc/profile报错-bash: id:command is not found

    由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...

随机推荐

  1. webapi 统一处理时间格式

    public class UnixDateTimeConvertor : DateTimeConverterBase { public override object ReadJson(JsonRea ...

  2. D5 F

    最近见到了好多跟排列有关的状压dp,好像略微会了一点,用 dp[i][s][j]表示第i位状态为s选择j的方案数,然后递推. 早起大概可以提高人的智商但是会导致人甚至不清,初始化写错了自闭了半个小时 ...

  3. vue2中使用transition

    最终效果为  div元素从右向左出现, 然后从左向右消失. transition标签包裹要移动的元素: css 样式: 其中: 1:  为div元素显示时的状态 2:  为div元素移动的过程 (进入 ...

  4. mybatis08--关联查询多对一

    根据省会的id查询出省会和对应国家的信息 01.多表的连接查询 修改对应的实体类信息 /** *国家的实体类 */ public class Country { private Integer cId ...

  5. js中的异步与同步,解决由异步引起的问题

    之前在项目中遇到过好多次因为异步引起的变量没有值,所以意识到了认识js中同步与异步机制的重要性 在单线程的js中,异步代码会被放入一个事件队列,等到所有其他代码执行后再执行,而不会阻塞线程. 下面是j ...

  6. 微信小程序本地的域名“不在以下request合法域名列表中”错误处理方法

  7. 动态获取移动端视宽,从而结合rem达到适配

    // jq !function(){ var windowWidth= $(window).width(); if(windowWidth > 750) { windowWidth = 750; ...

  8. 【zc】 php计算两个日期相隔多少年,多少月,多少日的函数

    /* *function:计算两个日期相隔多少年,多少月,多少天 *数据接受格式: '2014-12-03','2000-12-01'; *param string $date1[格式如:2011-1 ...

  9. 实际体验Span<T> 的惊人表现

    前言 最近做了一个过滤代码块功能的接口.就是获取一些博客文章做文本处理,然后这些博客文章的代码块太多了,很多重复的代码关键词如果被拿过来处理,那么会对文本的特征表示已经特征选择会有很大的影响.所以需要 ...

  10. UUID、GUID、SID、SUSID

    1. UUID: (Universally Unique Identifier) 通用唯一标识符, 是一个标识符标准用于软件架构,由开放软件基金会(OSF)作为分布式计算环境(DCE)的一部分而制作的 ...