Servlets & JSP Series 2 - Web APP Architecture
-
Servlets do not have a main() method, they are under the control of another Java application called a Container. Tomcat is an example of a container, when web server application gets a request for a servlet the server hands the request not to the servlet itself, but to the container in which the servlet is deployed, it’s the container that gives the servlet the HTTP request and response, and it’s the container that calls the servlet’s methods.
-
Container get to concentrate more on it own business logic instead of worrying about writing code for threading, security, and networking.
-
How the container handles a request: 1.User clicks a link that has a URL to a servlet instead of a static page; 2.The container “sees” that the request is for a servlet, so the container creates two objects: HttpServletResponse & HttpServletRequest; 3.The container finds the correct servlet based on the URL in the request, creates or allocates a thread for that request, and passes the request and response objects to the servlet thread; 4.The container calls the servlet’s service() method, depending on the type of request, the service() method calls either the doGet() or doPost() method; 5.The doGet() method generates the dynamic page and stuffs the page into the response object; 6.The thread completes, the container converts the response object into HTTP response, sends it back to the client, then deletes the request and response objects.
-
In the real world, 99 percent of all servlets override either the doGet() or doPost() method, 99 percent of all servlets are HttpServlets, servlet inherited from HttpServlet.
-
A servlet can have three names: 1.Client-know URL name; 2.Deployer-known secret internal name; 3.Actual file name.
-
When you deploy your servlet into your web Container, you will create a fairly simple XML document called the Deployment Descriptor to tell the Container how to run your servlets and JSPs, although you will use the DD for more than just mapping names, you will use two XML elements to map URLs to servlets-one to map the client-known public URL name to your own internal name, and the other to map your own internal name to a fully-qualified class name.
-
The deployment descriptor(DD) provides a “declarative” mechanism for customizing your web applications without touching source code.
-
The servlet does whatever it needs to do to process the request(like insert or search the database) and returns the HTML page in the HTTP response, all of the business logic and the client HTML page response is inside the servlet code.
-
Client fills out the DQL query form and submit, this send and HTTP POST request for the DoDQLQuery, then the web server invokes the servlet, the servlet runs the query on the database, then the request is forwarded to the appropriate JSP, then the JSP builds the response HTML and sends it back.
-
Model*View*Controller(MVC) takes business logic out of the servlet, and puts it in a “Model”-a reusable plain old java class, the model is a combination of the business data and the methods that operate on that data.
-
MVC in the Servlet & JSP world: 1.MODEL holds the real business logic and the state, in other words, it knows the rules for getting and updating the state, it’s the only part of the system that talks to the database; 2.VIEW is responsible for the presentation, it gets the state of the model from the controller, it’s also the part that gets the user input that goes back to the controller; 3.CONTROLLER takes user input from the request and figures out what it means to the model and tells the model to update itself, and makes the new model state available for the view.
-
A J2EE application server includes both a web container and an EJB container; Tomcat is a web container but not a full J2EE application server; A J2EE 1.4 server includes the Servlet spec 2,3, JSP spec 2.0, and EJB spec 2.1.
-
In the old days, say, the year 2000, could fine complete J2EE application servers, standalone web containers, and standalone EJB containers, but today, virtually all EJB containers are part of full J2EE servers, although there are still a few standalone web containers, including Tomcat and Resin, standalone web containers are usually configured to work with an HTTP web server(like Apache), although the Tomcat container does have the ability to act as a basic HTTP server, but for HTTP server capability, tomcat is not nearly as robust as robust as Apache, so the most common no-EJB web apps usually use Apache and Tomcat configured together-with Apache as the HTTP web server, and Tomcat as the web container, some of the most common J2EE servers are BEA’s WebLogic, the open source JBoss AS, and IBM’s WebSphere.
相关推荐
Head First Servlets&JSP;-第2版-高清扫描版-带详细书签 高清扫描版,书签比较详细,和目录一样
Head First Servlets & JSP(完好高清中文版)2.pdf 深入浅出 Servlets & JSP(完好高清中文版)2.pdf
深入浅出Servlets&JSP,感兴趣的人看一下吧
《Head First Servlets & JSP》是一本广受欢迎的教材,它深入浅出地讲解了这些概念,帮助开发者通过SCWCD(Sun Certified Web Component Developer)认证。以下是一些关键知识点的详细解释: 1. **Servlet**: - *...
Head First Servlets & JSP 完好高清中文版 part3 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。
这本书详细介绍了Servlets和JSP(JavaServer Pages)技术,它们是Java EE平台中的核心组件,用于构建动态、交互式的Web应用程序。 Servlets是Java编程语言中的一种服务器端扩展,它允许开发者创建能够处理HTTP请求...
【标题】"jstl&standard&jsp-api&servlet-api.jar" 涉及到的是四个关键的Java Web开发库,它们在构建基于Java的Web应用程序时起着至关重要的作用。这里,我们主要讨论JSTL(JavaServer Pages Standard Tag Library)...
head first servlets & JSP(2)
【标题】"head first servlet&JSP讲解课件java-web" 涉及的是Java Web开发中的核心组件——Servlet和JSP(JavaServer Pages)技术。Servlet是Java平台上的一个标准,用于创建动态Web应用程序,而JSP是Servlet的一种...
《Head First Servlets & JSP, Second Edition》是一本针对初学者的优秀教材,它深入浅出地介绍了Servlet和JSP这两个Java Web开发的核心技术。Servlet是Java平台上的服务器端编程接口,而JSP(JavaServer Pages)则...
### Java Web 开发技术详解:Servlets、JSP与EJB #### 一、概述 《Java for the Web with Servlets, JSP, and EJB》是一本全面介绍如何使用 Java 进行 Web 应用程序开发的专业书籍。本书不仅涵盖了 Servlet 2.3、...
Head First Servlets & JSP(完好高清中文版)1.pdf 深入浅出 Servlets & JSP(完好高清中文版)1.pdf
《Head First Servlets&JSP》应了最新的学习理论,能将知识直接送到你的大脑里。你会通过不寻常的方式同Servlet和JSP打交道,可以学得更深入、更快,而且更重要的是,你能真正地学以致用。你可以看看为什么那么多...
Head First Servlets & JSP 高清中文版 part2 共5部分
head first servlets & JSP(3)
Java Servlets 和 JSP(JavaServer Pages)是Java在Web开发中的两个核心技术,它们用于构建动态、交互式的网页应用程序。本教程将深入讲解这两个概念及其优势、安装配置、基本使用方法,以及如何处理请求和响应。 1...
《Java开发指南Servlets&JSP》是一本深入讲解Java Web开发的重要书籍,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心技术。在Java Web开发领域,Servlets和JSP是构建动态网站和Web应用程序的基础,它们为...
2. **Servlet配置**:Servlet的部署是在`web.xml`文件中完成的,其中包含了Servlet的映射、初始化参数、会话管理等配置。Servlet可以通过`@WebServlet`注解进行声明式配置,简化了XML配置。 3. **...
《Head First Servlets & JSP》是一本深受程序员喜爱的学习指南,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心的Java Web开发技术。Servlets是Java平台上的服务器端编程模型,而JSP则是用于创建动态网页...