`
Kayonlife
  • 浏览: 22415 次
  • 性别: Icon_minigender_1
  • 来自: 无锡
社区版块
存档分类
最新评论

Servlets & JSP Series 1 - Why do we use JSP

阅读更多

 

Servlets & JSP Series 1 - Why do we use JSP

 

  • Web由数以亿计的客户(浏览器)和服务器(Apache应用服务器)组成,这些客户和服务器之间通过有线和无线网络连接,Web服务器接收客户请求,然后向客户返回一些结果。
  • 客户的请求包含客户所找资源的名字和地址(URL),服务器通常有很多“内容”发给客户,这些内容可能是Web页面或其他资源,服务器的响应包含客户请求的具体文档(在无法处理客户的请求,返回一个错误值)。
  • Web客户允许用户请求服务器上的某个资源,并且向用户显示请求的结果,用户在浏览器上点击一个链接,浏览器对请求格式化,并把它发送给服务器,服务器找到所请求的页面,然后服务器格式化响应,并将其发送给客户,浏览器得到HTML,并显示给用户。
  • 客户和服务器要想通信,它们必须有一种共同的语言,在Web上,客户和服务器必须说HTTP,而且浏览器必须懂HTMLHTML告诉浏览器怎样向用户显示内容,HTTPWeb上客户和服务器之间通信所用的协议,服务器使用HTTP向客户发送HTML
  • HTML的目标是拿到一个文本文档,然后为它增加一些标记,告诉浏览器如何对这个文本格式化,浏览器读取HTML代码,创建Web页面,并将该页面显示给用户。
  • HTTP协议是TCP/IP的上层协议,TCP负责确保从一个网络节点向另一个网络节点发送的文件能作为一个完整的文件到达目的地,尽管在具体传送过程中这个文件可能会分解为小块传输,IP是一个底层协议,负责把数据块沿路由到达目的地,HTTP则是另一个网络协议,有一些Web特定的特性,不过它要依赖于TCP/IP从一处向另一处完整地传送请求和响应。
  • HTTP会话结构是一个简单的请求/响应序列:浏览器发出请求,服务器作出响应。
  • 请求流关键要素:HTTP方法(要完成的动作);要访问的页面(URL);表单参数(方法参数)。
  • 响应流的关键要素:状态码(表明是否成功);内容类型(包括文本、图片、HTML等等);内容(具体的HTML、图片等等)。
  • HTTP响应可以包含HTML,它还会在响应中包含的内容前面增加首部信息,HTML浏览器使用首部信息来帮助处理HTML页面。
  • HTTP在响应时,首先会看到一个HTTP方法名,道理和Java方法一样,方法名告诉服务器是哪一类请求,并指出消息中余下的部分该如何格式化,HTTP有很多方法,最常用的当属:GETPOST
  • GET:用户点击指向一个页面的链接,浏览器向服务器发送一个HTTP GET,请求服务器获得(GET)页面。
  • POST:用户填写表单,点击Submit(提交)按钮,浏览器向服务器发送一个HTTP POST,为服务器提供用户在表单中键入的信息。
  • Get is the simplest HTTP method, and its main job in life is to ask the server to get a resource and send it back. The point of GET is to get something back from server.
  • Post is more powerful request, it’s like a GET plus plus, with POST, you can request something and at the same time send form data to the server.
  • Get & Post are the two big ones that everybody uses. But there are a few rarely used methods including HEAD, TRACE, PUT, DELETE, OPTIONS, and CONNECT.
  • Also we can send a little data with HTTP GET, but the reason you might use POST instead of GET include: 1.The total amount of characters in a GET is really limited; 2.The data you send with the GET is appended to the URL up in the browser bar, so whatever you send is exposed; 3.The User cannot use bookmark a form submission if you use POST instead GET.
  • All the pieces on one page: 1.the user types a URL; 2. The browser create an HTTP GET request; 3.The HTTP GET is sent to the server; 4.The server finds the page; 5.The server generates an HTTP response; 6. The HTTP response is sent to the browser; 7. The browser renders the HTML; 8.Client looks forward to a successful page transaction.
  • For each description, circle either POST or GET depending on which HTTP method you’d choose for implementing that functionality.
  • Every resource on the web has its own unique address, URL format: 1.Protocal; 2.Server; 3.Port; 4.Path; 5.Resource.
  • Well-known TCP port numbers for common server applications: 1.FTP-21; 2.Telnet-23; 3. SMTP-25; 4.Time-37; 5.HTTP-80; 6.POP3-110; 7.HTTPS-443. The TCP port numbers from 0 to 1023 are reserved for well-known services(including the big one we care about-port 80). Better do not use these ports for our own custom server programs.
  • A static page just sits there in a directory. The server finds it and hands it back to the client as is. Every client sees the same thing.
  • If you need just-in-time pages(dynamically-created pages that do not exist before the request) and the ability to write/save data on the server(which means: writing to: 1.a file or 2.database), you cannot rely on the web server alone. Just-in-time pages do not exist before the request comes in. It’s like making an HTML page out of thin air. The request comes in, the helper app “writes” the HTML, and the web server gets it back to the client.
  • The non-Java term for a web server helper app is “CGI” program, CGI stands for Common Gateway Interface.
  • Servlets and CGI both play the role of a helper app in the web server.
  • Servlets demystified(write, deploy, run): 1. Build directory tree 2.Write a servlet named Ch1Servlet.java and put it in the src directory 3.Create a deployment descriptor(DD) named web.xml and put it in the etc directory 4.Build this directory tree under the existing tomcat directory 5.From the project1 directory, compile the servlet 6.Copy the Ch1Servlet.class file to WEB-INF/classes, and copy the web.xml file to WEB-INF 7.From the tomcat directory, start Tomcat 8.Launch your browser and type in the URL & Path 9.Every time you update either a servlet class or the deployment descriptor, shutdown Tomcat.
  • Actually, trying to format HTML inside a servlet’s out.println() pretty much sucks. A JSP page looks just like an HTML page, except you can put Java and Java-related things inside the page. So it really is like inserting a variable into your HTML.
  • JSP lets the Java programmer off the hook for writing HTML, but it doesn’t really help the HTML designer.
  • HTTP stands for Hypertext Transfer Protocol, and it the network protocol used on the Web. It runs on top of TCP/IP. HTTP uses a request/response model-the client makes an HTTP request, and the web server gives back an HTTP response that the browser then figures out how to handle.
  • If the response from the server is an HTML page, the HTML is added to the HTTP response, an HTTP request includes the request URL, the HTTP method, and form parameter data, an HTTP response includes a status code, the content-type, and the actual content of the response.
  • A GET request appends form data to the end of the URL, a POST request includes form data in the body of the request.
  • A MIME type tells the browser what kind of data the browser is about to receive so that the browser will know what to do with it.
  • URL stands for Uniform Resource Locator, every resource on the web has its own unique address in this format. It starts with a protocol, followed by the server name, an optional port number, and usually a specific path and resource name, it can also include an optional query string, if the URL is for a GET request.
  • Web servers are good at serving static HTML pages, but if you need dynamically-generated data in the page, you need some kind of helper app can work with the server. The non-Java term for these helper apps is CGI.
  • Putting HTML inside a println() statement is ugly and error-prone, but JSPs solve that problem by letting you put Java in to an HTML page rather than putting HTML into Java code.

 

1
0
分享到:
评论

相关推荐

    Head First Servlets&JSP;-第2版-高清扫描版-带详细书签

    Head First Servlets&JSP;-第2版-高清扫描版-带详细书签 高清扫描版,书签比较详细,和目录一样

    深入浅出Servlets&JSP.

    深入浅出Servlets&JSP,感兴趣的人看一下吧

    Head First Servlets & JSP(完好高清中文版)2.pdf

    Head First Servlets & JSP(完好高清中文版)2.pdf 深入浅出 Servlets & JSP(完好高清中文版)2.pdf

    Head First Servlets & JSP 学习笔记

    《Head First Servlets & JSP》是一本广受欢迎的教材,它深入浅出地讲解了这些概念,帮助开发者通过SCWCD(Sun Certified Web Component Developer)认证。以下是一些关键知识点的详细解释: 1. **Servlet**: - *...

    Head First Servlets & JSP(完好高清中文版).part3

    Head First Servlets & JSP 完好高清中文版 part3 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。

    jstl&standard&jsp-api&servlet-api.jar

    1. **JSTL (JavaServer Pages Standard Tag Library)**:JSTL是一套用于JavaServer Pages(JSP)的标签库,它提供了标准的标签来处理常见的任务,如迭代、条件判断、XML处理、国际化等,从而让JSP页面更加简洁、易读...

    Head First Servlets and JSP 中文版 第2版 PDF电子书下载 带书签目录 完整版.zip

    《Head First Servlets and JSP》是学习Java服务器端编程的经典教材,中文版的第二版为读者提供了深入浅出的学习路径,特别适合初学者和有经验的开发者进行自我提升。这本书详细介绍了Servlets和JSP(JavaServer ...

    Head First Servlets & JSP, Second Edition

    《Head First Servlets & JSP, Second Edition》是一本针对初学者的优秀教材,它深入浅出地介绍了Servlet和JSP这两个Java Web开发的核心技术。Servlet是Java平台上的服务器端编程接口,而JSP(JavaServer Pages)则...

    Head First Servlets & JSP(完好高清中文版)1.pdf

    Head First Servlets & JSP(完好高清中文版)1.pdf 深入浅出 Servlets & JSP(完好高清中文版)1.pdf

    Head First Servlets & JSP(完好高清中文版)

    《Head First Servlets&JSP》应了最新的学习理论,能将知识直接送到你的大脑里。你会通过不寻常的方式同Servlet和JSP打交道,可以学得更深入、更快,而且更重要的是,你能真正地学以致用。你可以看看为什么那么多...

    Head First Servlets & JSP(完好高清中文版).part1

    Head First Servlets & JSP 完好高清中文版 part1 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。

    head first servlets & JSP(3)

    head first servlets & JSP(3)

    head first servlets & JSP(2)

    head first servlets & JSP(2)

    JAVA - TUTOR SERVLETS & JSP

    Java Servlets 和 JSP(JavaServer Pages)是Java在Web开发中的两个核心技术,它们用于构建动态、交互式的网页应用程序。本教程将深入讲解这两个概念及其优势、安装配置、基本使用方法,以及如何处理请求和响应。 1...

    Head_First_Servlets_&_JSP_习题

    《Head First Servlets & JSP》是一本深受程序员喜爱的学习指南,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心的Java Web开发技术。Servlets是Java平台上的服务器端编程模型,而JSP则是用于创建动态网页...

    Head First Servlets & JSP(完好高清中文版).part6

    Head First Servlets & JSP 完好高清中文版 part6 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。

    Head First Servlets & JSP 高清中文版 part2

    Head First Servlets & JSP 高清中文版 part2 共5部分

    Jave开发指南Servlets&JSP

    《Java开发指南Servlets&JSP》是一本深入讲解Java Web开发的重要书籍,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心技术。在Java Web开发领域,Servlets和JSP是构建动态网站和Web应用程序的基础,它们为...

    Core Servlets & JSP_cn

    《Core Servlets & JSP_cn》是一本专为Java初学者设计的教程,全面涵盖了Servlets和JSP(JavaServer Pages)的核心技术。Servlets是Java Web开发中的基础组件,用于处理HTTP请求并生成动态响应,而JSP则是用于创建...

Global site tag (gtag.js) - Google Analytics