Web应用程序技术简介.doc_第1页
Web应用程序技术简介.doc_第2页
Web应用程序技术简介.doc_第3页
Web应用程序技术简介.doc_第4页
Web应用程序技术简介.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 Web应用程序技术简介1.1 计算机应用程序序号分类开发语言1GUI应用程序C、C+、C#、Basic(VB)、Pascal(Delphi)、Java、Fortran、PowerBuilder、2Web应用程序PHP、Visual C#、Visual Basic、Java、3其他应用程序C、C+、C#、Basic(VB)、Pascal(Delphi)、Java、Fortran、PowerBuilder、1.2 Web应用程序1.基本原理Internet、网络协议、客户机/服务器、HTTPHTTP:在每个连接中只支持一个请求主,即:客户端使用HTTP连接服务器获取一个文件之后断开连接。2.体系架构C/S : 胖客户机瘦服务器 P1-7 图 1-5B/S:瘦客户机胖服务器 P1-9 图1-63.基于HTTP的客户-服务器架构P1-9 图1-7: 请求(request)、响应(response)4.重要概念(1)Web应用程序(Web站点):HTML页面和其他多媒体文件的集合(包括CGI或Servlet处理) Web站点文件结构 P1-10 图 1-8(2)Web服务器:软件,服务器端HTTP组件。 第一个Web服务器:httpd 常用的Web服务器:IIS、Tomcat、GlassFish、Weblogic、JBoss、(3)Web服务:是Internat上由一个应用程序提供给另一个应用程序的服务,它们通常在B-to-B的事务中使用SOAP和扩展标记语言(XML)传输数据。1.3 Web服务器的CGI编程1. 通常,浏览器需要发送数据到服务器上的CGI程序。CGI规范定义数据如何打包和如何以HTTP请求的方式发送到服务器。2. URL决定执行哪个程序。这个程序也许是一个脚本或一个可执行文件。CGI程序解析请求中的CGI数据,处理数据,并产生一个应答(通常是HTML页面)。3. CGI应答被发送到Web服务器,服务器包装这个应答,以HTTP的形式返回到Web浏览器。P1-13 图1-9、 P1-14 图1-10、1-114. CGI程序的优缺点:优点:(1)虽然CGI程序主要由Perl编写,但它可以由多种语言写成(2)一个有Bug的CGI程序不会使Web服务器崩溃(3)程序易于引用,Web设计人员能够在一个Web页面中引用一个写好的脚本(4)因为CGI程序在它们的操作系统shell中执行,这些程序与执行同一个CGI程序的其他HTTP请求不会出现并发冲突(5)所有服务为CGI程序提供支持缺点:(1)CGI程序的应答时间很长,因为CGI程序在它们自己的OS Shell中执行,创建一个OS Shell对OS来说是个大的开销(2)CGI不具有升级性,例如,如果访问Web应用程序的人数从50增加到5000,CGI不能自我调整处理负载。因为一个计算机能运行的操作系统进程数是个有限的值(3)CGI语言不是安全和面向对象的(4)CGI脚本用于产生HTML应答,因此CGI代码和HTML混在一起,这不符合表示和业务逻辑分离原则(5)脚本语言具有平台依懒性1.4 Java Servlet1. 一个Java Servlet 是一个Java程序,Servlet能识别HTTP请求,动态产生应答(可能通过查询数据库来完成请求),然后发送包括HTML页面或文档的应答到浏览器2. Servlet采用组件容器(Web容器)架构,Web容器是一个JVM,它提供了Servlet API的实现。Servlet的实例是组件,它由Web容器管理,并应答HTTP请求3. Servlet执行 P1-17 图1-13、1-44. Java Servlet的优缺点优点:(1)每个请求在一个独立的线程中执行,因此Servlet请求的处理与传统的CGI处理上有很大的不同(2)Servlet有可升级性,能执行更多的请求,因为Web容器使用一个线程而不是操作系统进程,而线程使用有限的系统资源(3)Servlet是强壮的,是面向对象的(4)Servlet由Java编程语言编写、与平台无关(5)Servlet具有日志功能,多数CGI程序没有这个功能(6)Web容器给Servlet提供额外的服务,如错误处理和安全缺点:(1)Servlet通常嵌入业务逻辑和表示逻辑(2)Servlet必须要解决并发问题1.5 JavaServer Pages(JSP)技术1. JSP:实现HTML页面嵌入代码和使用模板数据的技术之一。使用JSP页面时,Java代码段嵌入到一个类似HTML的文件中。这个代码在运行时执行,创建动态内容。2. JSP页面象一个Servlet一样运行,任何一个在Servlet能作的事也能在JSP页面中做,主要的区别是一个JSP页面重点放在Web应用程序的表示逻辑上3. JSP技术优缺点优点:(1)使用JSP的Web应用程序具有很高的性能和升级性,因为它们使用线程而不是操作系统的shells或进程(2)JSP技术构建在Java技术之上,因此与本台无关(3)JSP脚本由Java语言编写,因此JSP页面能利用面向对象语言的优点和所有Java的APIs缺点:(1)JSP页面包括表示逻辑和业务逻辑(2)JSP页面也必须考虑并发问题(3)JSP页面不容易调试一个设计良好的Web应用程序应该同时使用Servlet和JSP页面,以实现关注的分离。1.6 Model 2架构1. Model 2架构使用一个变化的Model-View-Controller(MVC)设计模式,使Servlet和JSP结合实现关注的分离。2. Model 2架构设计的Web应用程序具有如下特征:(1)一个Servlet作为控制器,它验证表单数据,用表单数据更新模型,并选择下一个视图作为应答(2)JSP页面作为视图,提供HTML应答,从模型中获取必要的数据产生应答,并提供HTML表单为用户提供交互(3)Java类作为模型,它实现Web应用程序的业务逻辑3. 使用Model 2设计Web服务器架构 P1-23 图1-164. Model 2优点:快速、功能强大、容易创建、跨平台、可升级、易维护5. 成熟的Model 2框架: Jakarta工程的Struts1.7 J2EE平台 Servlet、JSP、EJB(Enterprise JavaBeans)P1-26 图1-17 J2EE架构例子:业务逻辑组件放在一个独立的层,可以由GUI应用程序或Web应用程序访问这些逻辑组件。1.8 大型的Web应用程序工作角色1. Web设计人员创建视图元素2. Web组件开发人员创建控制器角色3. 业务组件开发人员创建模型元素4. 数据访问开发人员创建数据库访问元素1.9 Web应用程序的变迁J2EE平台可实现四种类型的Web应用程序(1)静态HTML(2)HTML与基本的JSP和Servlet(3)JSP页面和JavaBeans组件(4)高度结构化的应用程序,使用模块化组件和企业beanP1-28 图1-18实验1 安装、配置JDK任务:(1)安装、配置JDK(2)解释、运行Java GUI应用程序(围棋对弈、华容道)实验2 安装、配置Tomcat任务:(1)安装、配置Tomcat(2)部署、运行Java Web应用程序(JSP程序SquaresServlet.war、Servlet程序 mod02_view.war)作业:1. What are the advantages and disadvantages of CGI?A:CGI programs have the following advantages:l Programs can be written in a variety of languages, although they are primarily written in Perll A CGI program with bugs does not crash the web server.l Programs are easy for a web designer to reference. When the script is written, the designer can reference it in one line in a web page.l Because CGI programs execute in their own OS shell, these programs do not have concurrency conflicts with other HTTP requests executing the same CGI program.l All service providers support CGI programs.CGI program also have the following distinct disadvantages:l The response time of CGI programs is high because CGI programs execute in their own OS shell. The creation of an OS shell is a heavyweight activity for the OS.l CGI is not scalable. If the number of people accessing the web application increases from 50 to 5000, for example, CGI cannot be adapted to handle the load. There is a limit on the number of separate operating system processes a computer can run.l The languages for CGI are not always secure or object-oriented.l The CGI script has to generate an HTML response, so the CGI code is mingled with HTML. This is not good separation of presentation and business logic.l Scripting language are often platform-dependent.2. What are the advantages and disadvantages of Servlet?A:Servlets have the following advantages:l Each request is run in a separate thread, so servlet request processing is significantly faster than traditional CGI processing.l Servlets are scalable. Many more requests can be executed because the web container uses a thread rather than an operating system process, which is a limited system resource.l Servlets are robust and object oriented. You have all the capabilities of the Java programming language when you written the servlet, instead of the capabilities of Perl or whatever language you use write the CGI script.l Servlets can only be written in the Java programming language, which makes them easy to write if you know the Java programming language. However, using servlets to generate pages with dynamic content requires application development expertise.l Servlets are platform independent because they are written in the Java programming language.l Servlets have access to logging capabilities, most CGI programs do not.l The web container provides additional services to the servlets, such as error handling and security.Servlets have the following disadvantages:l Servlets often contain both business logic and presentation logic.l Servlets must handle concurrency issues.3. What are the advantages and disa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论