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

代码如下:

@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. A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)

    出现这个问题,是因为关毕了appium,或者是关毕了appium再次打开,那么session就不是一样的了所以报错. 一般是因为测试的时候报错了,appium自动关毕了,再次打出现的报错 解决方法:重 ...

  2. Orders matters: seq2seq for set 实验

    论文提出了input的顺序影响seq2seq结果 有一些输入本身是无序的怎么去处理呢 作者提出LSTM controller的方式 替代输入的LSTM encode方式         作者实验这种方 ...

  3. VS2017 配置glfw3

    直接下载源码使用VS进行编译. 1. 源码下载地址http://www.glfw.org/download.html, 点击Source Package 2. 打开cmake-3.12.1-win32 ...

  4. flask将日志写入日志文件

    import logging logging.basicConfig(level=logging.DEBUG,#控制台打印的日志级别 filename='log_new.log', # 将日志写入lo ...

  5. TestNG 框架的运用

    TestNG这个测试框架可以很好的和基于Selenium的web自动化测试结合在一起,实现把我们写好的自动化测试用例以自定义顺序执行.下面分为十二步来对TestNG测试框架进行总结,包括环境的部署,从 ...

  6. mysql拿webshell总结

    1.select '<?php eval($_POST[jumbo]) ?>' into outfile '/var/www/jumbo.php'; 2.select '<?php ...

  7. react学习笔记01

    被项目拖了半年的我终于有时间学习react 了 下面是我最近学习的笔记 支持jsx语法 ReactDOM.render( <div> <h1>hello, word</h ...

  8. ArcGIS API for JavaScript经典例子

    地址为本地 1.绘制图形: http://localhost/arcgis_js_api/sdk/sandbox/sandbox.html?sample=toolbar_draw 2.双击编辑图形 h ...

  9. VBA语法总结

    为了控制Excel,学了些VBA,总结下语法,下文分为五部分: 一.代码组织 二.常用数据类型 三.运算符 四.控制流 五.常用内置函数 一.代码组织 1.能写代码的地方有{模块,类模块}. 2.代码 ...

  10. 解决web资源跨域请求问题

    参考地址: http://my.oschina.net/lichaoqiang/blog/317823 在浏览器请求中,出现跨域访问资源的问题,我们肯定会遇到.如果跨域请求被阻止,有可能导致css.j ...