What is a Servlet?
Servlet 工作原理解析
https://www.ibm.com/developerworks/cn/java/j-lo-servlet/index.html
你可以理解为,Spring MVC是基于servlet的,它有一个DispatherServlet,然后它负责处理请求,并且调用了你的controller。
打一个比方,web网站是应用程序么?你可以说浏览器是一个应用程序,而web网站是让浏览器这个应用程序作为基础,成为通用的应用的容器。
a small, server-resident program that typically runs automatically in response to user input.
What is a Servlet?
- A servlet is simply a class which responds to a particular type of network request - most commonly an HTTP request.
- Basically servlets are usually used to implement web applications - but there are also various frameworks which operate on top of servlets (e.g. Struts) to give a higher-level abstraction than the "here's an HTTP request, write to this HTTP response" level which servlets provide.
- Servlets run in a servlet container which handles the networking side (e.g. parsing an HTTP request, connection handling etc). One of the best-known open source servlet containers is Tomcat.
- In a request/response paradigm, a web server can serve only static pages to the client
- To serve dynamic pages, a we require Servlets.
- Servlet is nothing but a Java program
- This Java program doesn’t have a main method. It only has some callback methods.
- How does the web server communicate to the servlet? Via container or Servlet engine.
- Servlet lives and dies within a web container.
- Web container is responsible for invoking methods in a servlets. It knows what callback methods the Servlet has.
Flow of Request
- Client sends HTTP request to Web server
- Web server forwards that HTTP request to web container.
- Since Servlet can not understand HTTP, its a Java program, it only understands objects, so web container converts that request into valid request object
- Web container spins a thread for each request
- All the business logic goes inside doGet() or doPost() callback methods inside the servlets
- Servlet builds a Java response object and sends it to the container. It converts that to HTTP response again to send it to the client
How does the Container know which Servlet client has requested for?
- There’s a file called web.xml
- This is the master file for a web container
- You have information about servlet in this file-
- servlets
- Servlet-name
- Servlet-class
- servlet-mappings- the path like /Login or /Notifications is mapped here in
- Servlet-name
- url-pattern
- and so on
- Every servlet in the web app should have an entry into this file
- So this lookup happens like- url-pattern -> servlet-name -> servlet-class
How to "install" Servlets? * Well, the servlet objects are inherited from the library- javax.servlet.* . Tomcat and Spring can be used to utilize these objects to fit the use case.
Ref- Watch this on 1.5x- https://www.youtube.com/watch?v=tkFRGdUgCsE . This has an awesome explanation.
293
A servlet is simply a class which responds to a particular type of network request - most commonly an HTTP request. Basically servlets are usually used to implement web applications - but there are also various frameworks which operate on top of servlets (e.g. Struts) to give a higher-level abstraction than the "here's an HTTP request, write to this HTTP response" level which servlets provide.
Servlets run in a servlet container which handles the networking side (e.g. parsing an HTTP request, connection handling etc). One of the best-known open source servlet containers is Tomcat.
https://stackoverflow.com/questions/7213541/what-is-java-servlet
What is a Servlet?的更多相关文章
- servlet文件下载
创建web工程servlet,新建DownloadServlet.java package com.xmyself.servlet; import java.io.File; import java. ...
- java中servlet的各种路径
1. web.xml中<url-pattern>路径,(叫它Servlet路径!) > 要么以“*”开关,要么为“/”开头 2. 转发和包含路径 > *****以“/”开头:相 ...
- Servlet监听器笔记总结
监听器Listener的概念 监听器的概念很好理解,顾名思义,就是监视目标动作或状态的变化,目标一旦状态发生变化或者有动作,则立马做出反应. Servlet中的也有实现监听器的机制,就是Listene ...
- JavaWeb——Servlet
一.基本概念 Servlet是运行在Web服务器上的小程序,通过http协议和客户端进行交互. 这里的客户端一般为浏览器,发送http请求(request)给服务器(如Tomcat).服务器接收到请求 ...
- servlet 简介,待完善
什么是Servlet?① Servlet就是JAVA 类② Servlet是一个继承HttpServlet类的类③ 这个在服务器端运行,用以处理客户端的请求 Servlet相关包的介绍--javax. ...
- java web学习总结(五) -------------------servlet开发(一)
一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- servlet使用入门
创建web工程servlet,然后新建TestServlet.java package com.xmyself.servlet; import java.io.IOException; import ...
- 基于jsp+servlet图书管理系统之后台万能模板
前奏: 刚开始接触博客园写博客,就是写写平时学的基础知识,慢慢发现大神写的博客思路很清晰,知识很丰富,非常又价值,反思自己写的,顿时感觉非常low,有相当长一段时间没有分享自己的知识.于是静下心来钻研 ...
- [Servlet] 初识Servlet
什么是Servlet? 定义 Servlet的全称是 Server Applet,顾名思义,就是用 Java 编写的服务器端程序. Servlet 是一个 Java Web开发标准,狭义的Servle ...
- Java Servlet+Objective-c图上传 步骤详细
一. Servlet 1.创建图片保存的路径 在项目的WebContent下创建一个上传图片的专属文件夹. 这个文件夹创建后,我们保存的图片就在该文件夹的真实路径下,但是在项目中是无法看到上传的图片的 ...
随机推荐
- Matlab匿名函数
Matlab可以通过function去定义一些功能函数,这使得代码变得简洁和高效.但是如果遇到的是一些简单的数学公式组成的函数表达式,继续用function去定义函数,似乎显得有些冗杂和多余.这时候, ...
- DataTable 删除行 UpdateTable 方法
.不要使用DataTable.Rows.Remove(row) 而要使用 DataTable.Rows[i].Delete() .DataTable.Rows.Remove(row)相当于DataTa ...
- os-enviroment
pip3 install PyUserInput ping 是不带协议的
- Direct Buffer介绍
Direct Buffer 前言 上篇文章Buffer末尾中谈到堆内Buffer(Heap Buffer)和直接Buffer(Direct Buffer)的概念,但是却一笔带过,并未涉及其细节,这篇文 ...
- Jwt身份验证
转载自博友(TerryTon) 1.因为json是通用的,所以jwt可以在绝大部分平台可以通用,如java,python,php,.net等 2.基于jwt是无状态的,jwt可以用于分布式等现在比 ...
- 三分钟掌握,使用Quqrtz.Net实现定时发送邮件
在实际的项目中,常遇到延时触发工作以及定时触发工作 这里所讲的是借助第三方的组件 Quartz.Net 来实现(源码位置:https://github.com/quartznet/quartznet) ...
- linux memcached 的安装
linux memcached安装yum -y install libevent libevent-deve yum list memcached yum -y install memcached m ...
- android中app卡顿优化问题
所谓app卡顿原因就是在运行时出现了丢帧,还可能是UI线程被阻塞.首先来一下丢帧现象,android每16ms会对界面进行一次渲染,如果app的绘制.计算等超过了16ms那么只能等下一个16ms才能 ...
- Linux(Ubuntu)系统下使用crontab定期执行任务
安装cron(Ubuntu系统自带) apt-get install cron 开启crontab日志 默认情况下的日志是没有开启的,我们需要找到 /etc/rsyslog.d/50-default. ...
- Sql Server设置用户只能查看并访问特定数据库
现需要限定特定的用户只能查看并访问特定的数据库,防止多个用户对数据库操作时一些误操作. 参考i6first的如何让用户只能访问特定的数据库(MSSQL)博文 1.新建登录用户 以管理员身份登陆数据库( ...