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 ...
随机推荐
- js上传
有时候需要显示进度,这时候就需要做一些切割,具体上传代码如下: <!DOCTYPE HTML> <html lang="en-US"> <head&g ...
- mysql 命令行 备份 恢复数据
找到mysql启动位置 whereis mysql 备份指定数据库 包括表结构和数据 使用命令mysqldump 数据库名 -u 用户名 -p > 存储文件路径 [root@izm5e16gjd ...
- Spring Boot Starter 的基本封装
1)spring-boot-starter这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring-boot-starter-amqp通过spring-rabbit来 ...
- [转]MapReduce:详解Shuffle过程
Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...
- windows安装tomcat
1.打开官网http://tomcat.apache.org/ 2.在左侧的导航栏Download下方选择最新的Tomcat 9,点击页面下方的“ 64-bit Windows zip (pgp, m ...
- 关于Vue懒加载问题
有关Vue懒加载其实并不是想象的那么难和复杂: 首先引入 import VueLazyLoad from 'vue-lazyload'; 其次是使用 Vue.use(VueLazyLoad,{ er ...
- 转载:MySQL EXPLAIN 命令详解学习
转载自:https://blog.csdn.net/mchdba/article/details/9190771 MySQL EXPLAIN 命令详解 MySQL的EXPLAIN命令用于SQL语句的查 ...
- java Int 和 String 之间的转换
String 转换成 int Integer.parseInt(formParams.get("id")) int 转换成 string Integer.toString(id);
- jsp (二) 练习
package cn.sasa.serv; import java.io.IOException; import java.sql.SQLException; import java.util.Lis ...
- spring相关jar包
spring.jar是包含有完整发布的单个jar 包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下才会用到 spring-m ...