hello2 source anaylis
首先,我们先来看一看这一段的整体代码,
代码如下:
@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的更多相关文章
- Hello2 source analysis
在example目录下的web\servlet\hello2\src\main\java\javaeetutorial\hello2路径里可以找到hello2的GreetingServlet.java ...
- hello2 Source Analisis
hello2应用程序是一个web模块,它使用Java Servlet技术来显示问候和响应.此应用程序的源代码位于 _tut-install_/examples/web/servlet/hello2/目 ...
- hello2 source analisis(notes)
该hello2应用程序是一个Web模块,它使用Java Servlet技术来显示问候语和响应.使用文本编辑器查看应用程序文件,也可以使用NetBeans IDE. 此应用程序的源代码位于 _tut-i ...
- Analysis of Hello2 source code
Hello2 应用程序是一个 Web 模块,它使用 Java Servlet 技术来显示问候语和响应,使用的是 Java Servlet 技术. 该应用程序源代码在 tutorial-examples ...
- Analisis of Hello2 source
GreetingServlet.java @WebServlet("/greeting") //为servelt指定URL pattern为:/greeting public cl ...
- 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运行环境 ...
- 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 ...
- 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 ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
随机推荐
- PHP连接MySQL数据库的三种方式(mysql、mysqli、pdo)
PHP与MySQL的连接有三种API接口,分别是:PHP的MySQL扩展 .PHP的mysqli扩展 .PHP数据对象(PDO) ,下面针对以上三种连接方式做下总结,以备在不同场景下选出最优方案. P ...
- 初识springcloud
springcloud的基础是springboot,简单地说,就是通过写的springboot应用,使用springcloud集成. 在学习springcloud的过程中,自己的开发环境不能保证和博客 ...
- 关于图文转换的web工具
图文转换web服务提供的功能很简单,就是调用百度云提供的图文转换接口,将用户提供的图片中的文字识别返回给用户.具体功能就这个,但是该服务有用到以下的东西: 1.spring-boot web项目搭建 ...
- mui 窗口管理及窗口之间的数据传递
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- js设计模式(三)---代理模式
代理模式: 代理模式是为一个对象提供一个代理用品或占位符,以便控制对他的访问. 实现: 在 Web开发中,图片预加载是一种常用的技术,如果直接给某个 img 标签节点设置 src 属性,由于图片过大或 ...
- Python学习之旅(三十二)
Python基础知识(31):图形界面(Ⅱ) Python内置了turtle库,可以在计算机上绘图 运动控制: 1.画笔定位到坐标(x,y):turtle.goto(x,y) 2.向正方向运动 dis ...
- Selenium 3----控制浏览器操作
控制浏览器窗口大小 eg:将浏览器设置成移动端大小(480*800),进行访问 set_window_size()方法: from selenium import webdriver driver=w ...
- Python-----redis数据库
# redis数据库:基于内存的高性能key-value数据库,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到硬盘上进行保存:#缺点:1.数据库容量受到物理内存的限制, ...
- Q: Is Consul eventually or strongly consistent?
强一致 最终一致 Frequently Asked Questions - Consul by HashiCorp https://www.consul.io/docs/faq.html Q: Is ...
- Ubuntu系统实现将Jupyter notebook项目发布到GitHub
一.准备 Ubuntu16.04.GitHub账户.Git.Jupyter Notebook项目 二.打开Terminal(用户和邮箱即为你的GitHub注册的账号和邮箱) git config -- ...