外文文献及翻译----Servlet和JSP技术简述

合集下载

servlet概述

servlet概述

servlet概述1 什么是servlet? Servlet 是基于 Java 技术的 web 组件,容器托管的,⽤于⽣成动态内容。

像其他基于 Java 的组件技术⼀样,Servlet 也是基于平台⽆关的 Java 类格式,被编译为平台⽆关的字节码,可以被基于 Java 技术的 web server动态加载并运⾏。

Servlet是⼀种容器,有时候也叫做 servlet 引擎,是 web server 为⽀持 servlet 功能扩展的部分。

客户端通过 Servlet 容器实现的请求/应答模型与 Servlet 交互。

2 什么是servlet容器? Servlet 容器是 web server 或 application server 的⼀部分,提供基于请求/响应发送模型的⽹络服务,解码基于 MIME 的请求,并且格式化基于 MIME 的响应。

Servlet 容器也包含了管理 Servlet ⽣命周期。

Servlet 容器可以嵌⼊到宿主的 web server 中,或者通过 Web Server 的本地扩展 API 单独作为附加组件安装。

Servelt 容器也可能内嵌或安装到包含 web 功能的 application server 中。

所有 Servlet 容器必须⽀持基于 HTTP 协议的请求/响应模型,⽐如像基于 HTTPS(HTTP over SSL)协议的请求/应答模型可以选择性的⽀持。

容器必须实现的 HTTP 协议版本包含 HTTP/1.0 和 HTTP/1.1。

因为容器或许⽀持 RFC2616 (HTTP/1.1)描述的缓存机制,缓存机制可能在将客户端请求交给 Servlet 处理之前修改它们,也可能在将Servlet ⽣成的响应发送给客户端之前修改它们,或者可能根据 RFC2616 规范直接对请求作出响应⽽不交给 Servlet 进⾏处理。

Servlet 容器应该使 Servlet 执⾏在⼀个安全限制的环境中。

JSP技术简介

JSP技术简介

第1章JSP技术简介JSP(Java Server Pages)技术是由Sun公司发布的用于开发动态Web应用的一项技术。

它以其简单易学、跨平台的特性,在众多动态Web应用程序设计语言中异军突起,在短短几年中已经形成了一套完整的规范,并广泛地应用于电子商务等各个领域中。

在国内,JSP 现在也得到了比较广泛的重视,得到了很好的发展,越来越多的动态网站开始采用JSP技术。

本章就对JSP及其相关技术进行简单的介绍。

1.1 认识HTTP协议HTTP协议(Hypertext Transfer Protocol,超文本传送协议)是WWW服务器使用的主要协议,对HTTP协议细节的基本理解是编写JSP或Java小程序的开发人员所必需的。

因此在学习JSP技术之前有必要更加仔细地研究一下HTTP消息的格式(这里的讨论源自HTTP/1.1协议规范。

参见规范2616,网址为/rfc/rfc2616.txt)。

HTTP 协议的关键部分有HTTP请求和HTTP响应,以及客户端Web程序设计的一些基础知识,在第4章4.4节将会具体介绍。

1.2 客户端Web程序设计介绍Web浏览器现已成为深受大多数用户喜爱的用户界面。

HTML语言提供了丰富的控件,第三方厂商提供了Visual Basic编写的数百个额外的控件,这些都使得Web浏览器独具特色。

虽然Web浏览器与传统的GUI界面有一定的差距,但它提供了一种独立而又简单的方法来访问分布式资源,尤其是Internet资源。

而且越来越多的客户端Web程序扩展技术变得更加成熟,出现了包括CSS、JavaScript、VBScript、动态HTML、Java1.1.Applet应用程序等技术在内的客户端Web程序设计技术,它们的相互结合使得Web程序更加迷人。

下面简单介绍几种常用的客户端Web程序设计技术的特点。

本书假定读者对这些技术都有一定的了解,不对这些技术作详细介绍。

1.2.1 CSSCSS(Cascading Style Sheets)称为层叠样式表,是动态HTML技术的一个部分,但可以和HTML结合使用。

外文翻译---将Servlet和JSP组合使用

外文翻译---将Servlet和JSP组合使用

Combining JSP and ServletsThe technology of JSP and Servlet is the most important technology which use Java technology to exploit request of server, and it is also the standard which exploit business application .Java developers prefer to use it for a variety of reasons, one of which is already familiar with the Java language for the development of this technology are easy to learn Java to the other is "a preparation, run everywhere" to bring the concept of Web applications, To achieve a "one-prepared everywhere realized." And more importantly, if followed some of the principles of good design, it can be said of separating and content to create high-quality, reusable, easy to maintain and modify the application. For example, if the document in HTML embedded Java code too much (script), will lead the developed application is extremely complex, difficult to read, it is not easy reuse, but also for future maintenance and modification will also cause difficulties. In fact, CSDN the JSP / Servlet forum, can often see some questions, the code is very long, can logic is not very clear, a large number of HTML and Java code mixed together. This is the random development of the defects.Early dynamic pages mainly CGI (Common Gateway Interface, public Gateway Interface) technology, you can use different languages of the CGI programs, such as VB, C / C + + or Delphi, and so on. Though the technology of CGI is developed and powerful, because of difficulties in programming, and low efficiency, modify complex shortcomings,it is gradually being replaced by the trend. Of all the new technology, JSP / Servlet with more efficient and easy to program, more powerful, more secure and has a good portability, they have been many people believe that the future is the most dynamic site of the future development of technology.Similar to CGI, Servlet support request / response model. When a customer submit a request to the server, the server presented the request Servlet, Servlet responsible for handling requests and generate a response, and then gave the server, and then from the server sent to the customer. And the CGI is different, Servlet not generate a new process, but with HTTP Server at the same process. It threads through the use of technology, reduce the server costs. Servlet handling of the request process is this: When received from the client's request, calling service methods, the method of Servlet arrival of the first judgement is what type of request (GET / POST / HEAD…), then calls the appropriate treatment (DoGet / doP ost / doHead…) and generate a response.Although such a complex, in fact, simply said to Servlet is a Java class. And the general category of the difference is that this type operating in a Servlet container, which can provide session management and targeted life-cycle management. So that when you use the Servlet, you can get all the benefits of the Java platform, including the safety of the management, use JDBC access the database and cross-platform capability. Moreover, Servlet using thread, and can develop more efficient Web applications.JSP technology is a key J2EE technology, it at a higher level of abstraction of a Servlet.It allows conventional static and dynamic HTML content generated by combining an HTML page looks like, but as a Servlet to run. There are many commercial application server support JSP technology, such as BEA WebLogic, IBM WebSphere, JRun, and so on. JSP and Servlet use more than simple. If you have a JSP support for Web servers, and a JSP document, you can put it Fangdao any static HTML files can be placed, do not have to compile, do not have to pack, do not have to ClassPath settings, you can visit as ordinary Web It did visit, the server will automatically help you to do other work.JSP document looks like an ordinary static HTML document, but inside contains a number of Java code. It uses. Jsp the suffix, used to tell the server this document in need of special treatment. When we visit a JSP page, the document will first be translated into a JSP engine Java source files, is actually a Servlet, and compiler, and then, like other Servlet, from Servlet engine to handle. Servlet engine of this type loading, handling requests from customers, and the results returned to the customer, as shown below:Figure 1: Calling the process of JSP pagesAfter another visit this page to the customer, as long as the paper there have been no changes, JSP engine has been loaded directly call the Servlet. If you have already been modified, it will be once again the implementation of the above process, translate, compile and load. In fact, this is the so-called "first person to punishment." Because when the first visit to the implementation of a series of the above process, so will spend some time after such a visit would not.Java servlets offer a powerful API that provides access to all the information about the request, the session, and the application. combining JSP with servlets lets you clearly separate the application logic from the presentation of the application; in other words, it lets you use the most appropriate component type for the roles of Model, View and Controller.Servlets, Filters, and ListenersA servlet is a Java class that extends a server with functionality for processing a request and producing a response. It's implemented using the classes and interfaces defined by the Servlet API. The API consists of two packages: the javax.servlet package contains classes and interfaces that are protocol-independent, while the javax.servlet.http package provides HTTP-specific extensions and utility classes.What makes a servlet a servlet is that the class implements an interface named javax.servlet.Servlet, either directly or by extending one of the support classes. This interface defines the methods used by the web container to manage and interact with theservlet. A servlet for processing HTTP requests typically extends the javax.servlet.http.HttpServlet class. This class implements the Servlet interface and provides additional methods suitable for HTTP processing.Servlet LifecycleThe web container manages all aspects of the servlet's lifecycle. It creates an instance of the servlet class when needed, passes requests to the instance for processing, and eventually removes the instance. For an HttpServlet, the container calls the following methods at the appropriate times in the servlet lifecycle.Besides the doGet( ) and doPost( ) methods, there are methods corresponding to the other HTTP methods: doDelete( ), doHead( ), doOptions( ), doPut( ), and doTrace( ). Typically you don't implement these methods; the HttpServlet class already takes care of HEAD, OPTIONS, and TRACE requests in a way that's suitable for most servlets, and the DELETE and PUT HTTP methods are rarely used in a web application.It's important to realize that the container creates only one instance of each servlet. This means that the servlet must be thread safe -- able to handle multiple requests at the same time, each executing as a separate thread through the servlet code. Without getting lost in details, you satisfy this requirement with regards to instance variables if you modify the referenced objects only in the init( ) and destroy( ) methods, and just read them in the request processing methods.Compiling and Installing a ServletTo compile a servlet, you must first ensure that you have the JAR file containing all Servlet API classes in the CLASSPATH environment variable. The JAR file is distributed with all web containers. Tomcat includes it in a file called servlet.jar, located in the common/lib directory. On a Windows platform, you include the JAR file in the CLASSPATH.. Reading a RequestOne of the arguments passed to the doGet( ) and doPost( ) methods is an object that implements the HttpServletRequest interface. This interface defines methods that provide access to a wealth of information about the request.Generating a ResponseBesides the request object, the container passes an object that implements the HttpServletResponse interface as an argument to the doGet( ) and doPost( ) methods. This interface defines methods for getting a writer or stream for the response body. It also defines methods for setting the response status code and headers.Using Filters and ListenersThe servlet specification defines two component types beside servlets: filters and listeners. These two types were introduced in the Servlet 2.3 specification, so if you're using a container that doesn't yet support this version of the specification, I'm afraid you'reout of luck.FiltersA filter is a component that can intercept a request targeted for a servlet, JSP page, or static page, as well as the response before it's sent to the client. This makes it easy to centralize tasks that apply to all requests, such as access control, logging, and charging for the content or the services offered by the application. A filter has full access to the body and headers of the request and response, so it can also perform various transformations. One example is compressing the response body if the Accept-Language request header indicates that the client can handle a compressed response.A filter can be applied to either a specific servlet or to all requests matching a URL pattern, such as URLs starting with the same path elements or having the same extension. ListenersListeners allow your application to react to certain events. Prior to Servlet 2.3, you could handle only session attribute binding events (triggered when an object was added or removed from a session). You could do this by letting the object saved as a sessionattribute(using the HttpSession.setAttribute() method)implement the HttpSessionBindingListener interface. With the new interfaces introduced in the 2.3 version of the specification, you can create listeners for servlet context and session lifecycle events as well as session activation and passivation events (used by a container that temporarily saves session state to disk or migrates a session to another server). A newsession attribute event listener also makes it possible to deal with attribute binding events for all sessions in one place, instead of placing individual listener objects in each session.The new types of listeners follow the standard Java event model. In other words, a listener is a class that implements one or more of the listener interfaces. The interfaces define methods that correspond to events. The listener class is registered with the container when the application starts, and the container then calls the event methods at the appropriate times.Initializing Shared Resources Using a ListenerBeans like this typically need to be initialized before they can be used. For instance, they may need a reference to a database or some other external data source and may create an initial information cache in memory to provide fast access even to the first request for data. You can include code for initialization of the shared resources in the servlet and JSP pages that need them, but a more modular approach is to place all this code in one place and let the other parts of the application work on the assumption that the resources are already initialized and available. An application lifecycle listener is a perfect tool for this type of resource initialization. This type of listener implements the javax.servlet.ServletContextListener interface, with methods called by the container when the application starts and when it shuts down.Picking the Right Component Type for Each TaskThe Project Billboard application introduced is a fairly complex application. Half thepages are pure controller and business logic processing, it accesses a database to authenticate users, and most pages require access control. In real life, it would likely contain even more pages, for instance, pages for access to a shared document archive, time schedules, and a set of pages for administration. As the application evolves, it may become hard to maintain as a pure JSP application. It's easy to forget to include the access control code in new pages.This is clearly an application that can benefit from using a combination of JSP pages and the component types defined by the servlet specification for the MVC roles. Let's look at the main requirements and see how we can map them to appropriate component types:●Database access should be abstracted, to avoid knowledge of a specific dataschema or database engine in more than one part of the application: beans in therole of Model can be used to accomplish this.●The database access beans must be made available to all other parts of theapplication when it starts: an application lifecycle event listener is the perfectcomponent type for this task.●Only authenticated users must be allowed to use the application: a filter canperform access control to satisfy this requirement.●Request processing is best done with Java code: a servlet, acting as the Controller,fits the bill.●It must be easy to change the presentation: this is where JSP shines, acting as theView.Adding servlets, listeners, and filters to the mix minimizes the need for complex logic in the JSP pages. Placing all this code in Java classes instead makes it possible to use a regular Java compiler and debugger to fix potential problems.Centralized Request Processing Using a ServletWith a servlet as the common entry point for all application requests, you gain control over the page flow of the application. The servlet can decide which type of response to generate depending on the outcome of the requested action, such as returning a common error page for all requests that fail, or different responses depending on the type of client making the request. With the help from some utility classes, it can also provide services such as input validation, I18N preparations, and in general, encourage a more streamlined approach to request handling.When you use a servlet as a Controller, you must deal with the following basic requirements:●All requests for processing must be passed to the single Controller servlet.●The servlet must be able to distinguish requests for different types of processing.Here are other features you will want support for, even though they may not be requirements for all applications:● A strategy for extending the application to support new types of processingA mechanism for changing the page flow of the application without modifyingcode.Mapping Application Requests to the ServletThe first requirement for using a Controller servlet is that all requests must pass through it. This can be satisfied in many ways. If you have played around a bit with servlets previously, you're probably used to invoking a servlet with a URI that starts with /myApp/servlet. This is a convention introduced by Suns Java Web Server (JWS), the first product to support servlets before the API was standardized. Most servlet containers support this convention today, even though it's not formally defined in the servlet specification.将Servlet和JSP组合使用Servlet和JSP技术是用Java开发服务器端应用的主要技术,是开发商务应用表示端的标准。

javaweb英文参考文献

javaweb英文参考文献

javaweb英文参考文献以下是关于JavaWeb的英文参考文献的相关参考内容:1. Deepak Vohra. Pro XML Development with Java Technology. Apress, 2006.This book provides a comprehensive guide to XML development with Java technology. It covers topics such as XML basics, XML parsing using Java, XML validation, DOM and SAX APIs, XSLT transformation, XML schema, and SOAP-based web services. The book also includes numerous code examples and case studies to illustrate the concepts.2. Robert J. Brunner. JavaServer Faces: Introduction by Example. Prentice Hall, 2004.This book introduces the JavaServer Faces (JSF) framework, which is a part of the Java EE platform for building web applications. It provides a step-by-step guide to building JSF applications using various components and features such as user interface components, data validation, navigation handling, and backing beans. The book also covers advanced topics such as internationalization and security.3. Brett McLaughlin. Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam. O'Reilly Media, 2008. This book is a comprehensive guide to the development of Java web applications using Servlets and JavaServer Pages (JSP). It covers topics such as HTTP protocol, Servlet lifecycle, request andresponse handling, session management, JSP syntax and directives, JSTL and EL expressions, deployment descriptors, and web application security. The book also includes mock exam questions to help readers prepare for the Sun Certified Web Component Developer exam.4. Hans Bergsten. JavaServer Pages, 3rd Edition. O'Reilly Media, 2011.This book provides an in-depth guide to JavaServer Pages (JSP) technology, which is used for creating dynamic web content. It covers topics such as JSP syntax, scriptlets and expressions, JSP standard actions, JSP custom tag libraries, error handling, JSP with databases, JSP and XML, and internationalization. The book also includes examples and best practices for using JSP effectively.5. Marty Hall, Larry Brown. Core Servlets and JavaServer Pages, 2nd Edition. Prentice Hall, 2003.This book is a comprehensive guide to building Java web applications using Servlets and JavaServer Pages (JSP). It covers topics such as Servlet API, HTTP protocol, session management, request and response handling, JSP syntax and directives, JSP custom tag libraries, database connectivity, and security. The book also includes numerous code examples and case studies to demonstrate the concepts.6. Michael Ernest. Java Web Services in a Nutshell. O'Reilly Media, 2003.This book provides a comprehensive reference to Java-based web services technology. It covers topics such as SOAP, WSDL, UDDI, and XML-RPC protocols, as well as Java API for XML-based web services (JAX-WS) and Java API for RESTful web services (JAX-RS). The book also includes examples and best practices for developing and deploying web services using Java technology. Please note that the above references are just a selection of some of the available books on the topic of JavaWeb. There are numerous other resources available that can provide more detailed information on specific aspects of JavaWeb development.。

servlet技术简介

servlet技术简介

Servlet技术是Sun公司提供的一种实现动态网页的解决方案,它是基于Java编程语言的WEB服务器端编程技术,主要用于在WEB服务器端获得客户端的访问请求信息和动态生成对客户端的响应消息。

Servlet技术也是JSP技术(另外一种动态网页开发技术)的基础。

一个Servlet程序就是一个实现了特殊接口的Java类,用于被支持Servlet的WEB服务器调用和运行,即只能运行于具有Servlet引擎的WEB服务器端。

一个Servlet程序负责处理它所对应的一个或一组URL地址的访问请求,接收访问请求信息和产生响应内容。

Applet是用于浏览器端的Java小程序,在浏览器端被解释执行,用于在HTML网页中实现一些桌面应用程序的功能,被称为“小应用程序”。

Servlet是用于WEB服务器端的Java小程序,它在WEB服务器端被解释执行,用于处理客户端的请求和产生动态网页内容。

源于Applet的命名,这种WEB服务器端的Java小程序就被命名为了Servlet,与Applet相对应,Servlet可以被称之为“小服务程序”。

Servlet与普通java程序相比,只是输入信息的来源和输出结果的目标不一样,所以,普通Java程序所能完成的大多数任务,Servlet程序都可以完成。

Servlet程序具有如下的一些基本功能:l 获取客户端通过HTML的FORM表单递交的数据和URL后面的参数信息;l 创建对客户端的响应消息内容;l 访问服务器端的文件系统;l 连接数据库并开发基于数据库的应用;l 调用其它的Java类。

Servlet是运行在服务器端的多线程纯java程序,它处理请求的信息并将信息发送到客户端。

这样说吧其实你的JSP页面在客户端请求过后会由WEB容器转译成Servlet源代码,再将Servlet源代码经过编译加载到内存中执行,最后把结果响应给客户端。

====================================================================== =========================================servlet简介servlet容器:负责处理客户请求、把请求传送给servlet并把结果返回给客户。

外文文献翻译-JSP发展历史中英文

外文文献翻译-JSP发展历史中英文

JSP的技术发展历史作者:Kathy Sierra and Bert Bates来源:Servlet&JSPJava Server Pages(JSP)是一种基于web的脚本编程技术,类似于网景公司的服务器端Java 脚本语言—— server—side JavaScript(SSJS)和微软的Active Server Pages(ASP)。

与SSJS和ASP相比,JSP具有更好的可扩展性,并且它不专属于任何一家厂商或某一特定的Web服务器。

尽管JSP规范是由Sun公司制定的,但任何厂商都可以在自己的系统上实现JSP。

在Sun正式发布JSP(Java Server Pages)之后,这种新的Web应用开发技术很快引起了人们的关注。

JSP为创建高度动态的Web应用提供了一个独特的开发环境。

按照Sun的说法,JSP能够适应市场上包括Apache WebServer、IIS4.0在内的85%的服务器产品。

本文将介绍JSP相关的知识,以及JavaBean的相关内容,当然都是比较粗略的介绍其中的基本内容,仅仅起到抛砖引玉的作用,如果读者需要更详细的信息,请参考相应的JSP的书籍。

1。

1 概述JSP(Java Server Pages)是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准,其在动态网页的建设中有其强大而特别的功能。

JSP与Microsoft的ASP技术非常相似.两者都提供在HTML代码中混合某种程序代码、由语言引擎解释执行程序代码的能力。

下面我们简单的对它进行介绍.JSP页面最终会转换成servlet。

因而,从根本上,JSP页面能够执行的任何任务都可以用servlet 来完成。

然而,这种底层的等同性并不意味着servlet和JSP页面对于所有的情况都等同适用.问题不在于技术的能力,而是二者在便利性、生产率和可维护性上的不同。

毕竟,在特定平台上能够用Java 编程语言完成的事情,同样可以用汇编语言来完成,但是选择哪种语言依旧十分重要.和单独使用servlet相比,JSP提供下述好处:1)JSP中HTML的编写与维护更为简单。

计算机外文翻译---JSP应用框架

计算机外文翻译---JSP应用框架

外文翻译原文及译文JSP application frameworksWhat are application frameworks:A framework is a reusable, semi-complete application that can be specialized toproduce custom applications [Johnson]. Like people, software applications are more alike than they are different. They run on the same computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products.A framework provides developers with a set of backbone components that have the following characteristics:1.They are known to work well in other applications.2. They are ready to use with the next project.3. They can also be used by other teams in the organization.Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are done—but how long will it be before you can roll your own? If you buy it, you will have to climb the learning curve—and how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.Other types of frameworks:The idea of a framework applies not only to applications but to application componentsas well. Throughout this article, we introduce other types of frameworks that you can use with Struts. These include the Lucene search engine, the Scaffold toolkit, the Struts validator, and the Tiles tag library. Like application frameworks, these tools providecomponent.Some frameworks have been linked to a proprietary development environment. This is not the case with Struts or any of the other frameworks shown in this book. You can use any development environment with Struts: Visual Age for Java, JBuilder, Eclipse, Emacs, and Textpad are all popular choices among Struts developers. If you can use it with Java, you can use it with Struts.Enabling technologies:Applications developed with Struts are based on a number of enabling technologies.These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP. As a Struts developer, you don’t need to be an alphabet soup guru, but a working knowledge of these base technologies can help you devise creative solutions to tricky problems.Hypertext Transfer Protocol (HTTP):When mediating talks between nations, diplomats often follow a formal protocol.Diplomatic protocols are designed to avoid misunderstandings and to keep negotiations from breaking down. In a similar vein, when computers need to talk, they also follow a formal protocol. The protocol defines how data is transmitted and how to decode it once it arrives. Web applications use the Hypertext Transfer Protocol (HTTP) to move data between the browser running on your computer and the application running on the server.Many server applications communicate using protocols other than HTTP. Some of these maintain an ongoing connection between the computers. The application server knows exactly who is connected at all times and can tell when a connection is dropped. Because they know the state of each connection and the identity of each person using it, these are known as stateful protocols.By contrast, HTTP is known as a stateless protocol. An HTTP server will accept any request from any client and will always provide some type of response, even if the response is just to say no. Without the overhead of negotiating and retaining a connection, stateless protocols can handle a large volume of requests. This is one reason why theInternet has been able to scale to millions of computers.Another reason HTTP has become the universal standard is its simplicity. An HTTP request looks like an ordinary text document. This has made it easy for applications to make HTTP requests. You can even send an HTTP request by hand using a standard utility such as Telnet. When the HTTP response comes back, it is also in plain text that developers can read.The first line in the HTTP request contains the method, followed by the locationof the requested resource and the version of HTTP. Zero or more HTTP request headers follow the initial line. The HTTP headers provide additional information to the server. This can include the browser type and version, acceptable document types, and the browser’s cookies, just to name a few. Of the s even request methods, GET and POST are by far the most popular.Once the server has received and serviced the request, it will issue an HTTP response. The first line in the response is called the status line and carries the HTTP protocol version, a numeric status, and a brief description of the status. Following the status line, the server will return a set of HTTP response headers that work in a way similar to the request headers.As we mentioned, HTTP does not preserve state information between requests.The server logs the request, sends the response, and goes blissfully on to the next request. While simple and efficient, a stateless protocol is problematic for dynamic applications that need to keep track of their users. (Ignorance is not always bliss.Cookies and URL rewriting are two common ways to keep track of users between requests. A cookie is a special packet of information on the user’s computer. URL rewriting stores a special reference in the page address that a Java server can use to track users. Neither approach is seamless, and using either means extra work when developing a web application. On its own, a standard HTTP web server does not traffic in dynamic content. It mainly uses the request to locate a file and then returns that file in the response. The file is typically formatted using Hypertext Markup Language (HTML) [W3C, HTML] that the web browser can format and display. The HTML page often includes hypertext links to other web pages and may display any number of other goodies, such as images andvideos. The user clicks a link to make another request, and the process begins a new.Standard web servers handle static content and images quite well but need a helping hand to provide users with a customized, dynamic response.DEFINITION:Static content on the Web comes directly from text or data files, like HTML or JPEG files. These files might be changed from time to time, but they are not altered automatically when requested by a web browser. Dynamic content, on the other hand, is generated on the fly, typically in response to an individualized request from a browser.Common Gateway Interface (CGI):The first widely used standard for producing dynamic content was the Common Gateway Interface (CGI). CGI uses standard operating system features, such as environment variables and standard input and output, to create a bridge, or gateway, between the web server and other applications on the host machine. The other applications can look at the request sent to them by the web server and create a customized response.When a web server receives a request that’s intended for a CGI program, it runs that program and provides the program with information from the incoming request. The CGI program runs and sends its output back to the server. The web server then relays the response to the browser.CGI defines a set of conventions regarding what information it will pass as environment variables and how it expects standard input and output to be used. Like HTTP, CGI is flexible and easy to implement, and a great number of CGI-aware programs have been written.The main drawback to CGI is that it must run a new copy of the CGI-aware program for each request. This is a relatively expensive process that can bog down high-volume sites where thousands of requests are serviced per minute. Another drawback is that CGI programs tend to be platform dependent. A CGI program written for one operating system may not run on another.Java servlets:Sun’s Java Servlet platform directly addresses the two main drawbacks of CGIconventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM).A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications.The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets.To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet.But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs. Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces, so that they can be shared between requests. Acquiring resources like these can take several seconds—which is longer than many surfers are willing to wait.The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by Alan R. Williamson [Williamson]. The definitive source for Servlet information is the Java Servlet Specification [Sun, JST].JavaServer Pages:While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML. Code that looks like:out.println("<P>One line of HTML.</P>");out.println("<P>Another line of HTML.</P>");is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers.Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>.To be seen as a JSP page, the file just needs to be saved with an extension of .jsp.When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class file—just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again.Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.JavaBeans:JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components.DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the bean’s internal stat e through two flavors of methods: accessors are used to read a JavaBean’s state; mutators are used to change a JavaBean’s state.Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always void—mutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. The mutator method signature for a weight property of the type Double would be:public void setWeight(Double weight)A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator. Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters.The accessor method signature for our weight property is:public Double getWeight()If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name.be a logical value—either boolean or Boolean. Logical accessors cannot accept parameters in their method signature.The boolean accessor method signature for an on property would bepublic boolean isOn()The canonical method signatures play an important role when working with Java- Beans. Other components are able to use the Java Reflec tion API to discover a JavaBean’s properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the bean’s properties.Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the bean’s properties to customize the output.For more on JavaBeans, we highly recommend The Awesome Power of JavaBeans, by Lawrence H. Rodrigues [Rodrigues]. The definitive source for JavaBean information is the JavaBean Specification [Sun, JBS].Model 2:The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers.Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work.The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. Awith JSP pages.Summary:In this article, we introduced Struts as an application framework. We examined the technology behind HTTP, the Common Gateway Interface, Java servlets, JSPs, and JavaBeans. We also looked at the Model 2 application architecture to see how it is used to combine servlets and JSPs in the same application.Now that you have had a taste of what it is like to develop a web application with Struts, in chapter 2 we dig deeper into the theory and practice behind the Struts architecture.JSP 应用框架什么是应用框架:框架(framework)是可重用的,半成品的应用程序,可以用来产生专门的定制程序。

【计算机专业文献翻译】JSP概述

【计算机专业文献翻译】JSP概述

JSP介绍J2EE(Java2企业版)已经承担起了曾经很混乱的建立互联网平台的任务,并使开发者们能够使用Java来高效地创建多层服务器端应用程序。

现今,Java企业版的API已经扩展为涵盖了众多领域:用于远程对象处理的RMI和CORBA,用于数据库交互的JDBC,用于访问命名和目录服务的JNDI,用于创建可重用商务组件的企业级JavaBeans(EJB),用于面向消息的中间件的JMS TM(Java Messaging Service,Java消息服务),用于XML处理的JAXP TM,以及用于执行原子性(atomic)事务的JTA TM(Java Transaction API,Java事务API)。

另外,J2EE还支持servlets是一种非常流行的用于替代CGI脚本的Java小程序。

这些技术的组合使得程序员可以为各种不同的任务创建分布式的商务解决方案。

在1999年末,Sun Microsystems公司向企业级Java工具集中加入了一个新的元素:Java Server Pages(JSP,Java服务器页面)。

JSP建立在Java servlet之上,它的设计目的是使程序员乃至非程序员都能高效地创建Web内容。

什么是JSP?简明扼要地说,JSP是一种用来开发含有动态内容网页的技术。

纯HTML页面只包含静态的内容,它的内容通常保持不变,而JSP页面则不同,它可以根据任意数量的变量来改变自己的内容,这些变量包括用户的身份信息,用户使用的浏览器类型,用户提供的信息,以及用户所做的选择等。

JSP页面就和常规的网页一样,包含标准的标记语言元素,例如HTML的标签。

然而,JSP页面还包含特殊的JSP元素,这些元素使得服务器可以把动态内容插入到网页中。

JSP 元素的用途非常广泛,例如从数据库取得信息,或记录用户的个性信息。

当用户请求一个JSP页面时,服务器先执行JSP元素,并把结果同网页的静态部分相结合,然后把动态合成后的页面送回到浏览器。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

毕业设计(论文) 外文文献翻译专业学生姓名班级学号指导教师XX 学院外文资料名称:An Overview of Servletand JSP Technology外文资料出处:Internet附件: 1.外文资料翻译译文2.外文原文指导教师评语:签名:年月日Servlet和JSP技术简述Nagle and WiegleyXX译摘要:Servlet程序在服务器端运行,动态地生成Web页面与传统的CGI和许多其他类似CGI的技术相比,Java Servlet具有更高的效率,更容易使用,功能更强大,具有更好的可移植性,更节省投资。

关键字:JSP技术,Servlet,HTTP服务1.1Servlet的功能Servlets是运行在Web或应用服务器上的Java程序,它是一个中间层,负责连接来自Web浏览器或其他HTTP客户程序的请求和HTTP服务器上的数据库或应用程序。

Servlet的工作是执行西门的任务,如图1.1所示。

图1.1Web中间件的作用(1)读取客户发送的显式数据。

最终用户一般在页面的HTML表单中输入这些数据。

然而,数据还有可能来自applet或定制的HTTP客户程序。

(2)读取由浏览器发送的隐式请求数据。

图1.1中显示了一条从客户端到Web服务器的单箭头,但实际上从客户端传送到Web服务器的数据有两种,它们分别为用户在表单中输入的显式数据,以及后台的HTTP信息。

两种数据都很重要。

HTTP信息包括cookie、浏览器所能识别的媒体类型和压缩模式等。

(3)生成结果。

这个过程可能需要访问数据库、执行RMI或EJB调用、调用Web服务,或者直接计算得出对应的响应。

实际的数据可能存储在关系型数据库中。

该数据库可能不理解HTTP,或者不能返回HTML形式的结果,所有Web浏览器不能直接与数据库进行会话。

即使它能够做到这一点,为了安全上的考虑,我们也不希望让它这么做。

对应大多数其他应用程序,也存在类似的问题。

因此,我们需要Web中间层从HTTP流中提取输入数据,与应用程序会话,并将结果嵌入到文档中。

(4)向客户发送显式数据(即文档)。

这个文档可以用各种格式发送,包括文本(HTML或XML),二进制(GIF图),甚至可以式建立在其他底层格式之上的压缩格式,如gzip。

但是,到目前为止,HTML 式最常用的格式,故而servelt和JSP的重要任务之一就式将结果包装到HTML中。

(5)发送隐式的HTTP响应数据。

图1.1中显示了一条从Web中间层到客户端的单箭头。

但是,实际发送的数据有两种:文档本身,以及后台的HTTP信息。

同样,两种数据对开发来说都式至关重要的。

HTTP响应数据的发送过程涉及告知浏览器或其他客户程序所返回文档的类型(如HTML),设置cookie和缓存参数,以及其他类似的任务。

1.2动态构建网页的原因预先建立的文档可以满足客户的许多请求,服务器无需调用servlet就可以处理这些请求。

然而,许多情况下静态的结果不能满足要求,我们需要针对每个请求生成一个页面。

实时构建页面的理由有很多种:1、网页基于客户发送的数据。

例如,搜索引擎生成的页面,以及在线商店的订单确认页面,都要针对特定的用户请求而产生。

在没有读取到用户提交的数据之前,我们不知道应该显示什么。

要记住,用户提交两种类型的数据:显示(即HTML表单的数据)和隐式(即HTTP请求的报头)。

两种输入都可用来构建输出页面。

基于cookie值针对具体用户构建页面的情况尤其普遍。

2、页面由频繁改变的数据导出。

如果页面需要根据每个具体的请求做出相应的改变,当然需要在请求发生时构建响应。

但是,如果页面周期性地改变,我们可以用两种方式来处理它:周期性地在服务器上构建新的页面(和客户请求无关),或者仅仅在用户请求该页面时再构建。

具体应该采用哪种方式要根据具体情况而定,但后一种方式常常更为方便,因为它只需简单地等待用户的请求。

例如,天气预报或新闻网站可能会动态地构建页面,也有可能会返回之前构建的页面(如果它还是最新的话)。

3、页面中使用了来自公司数据库或其他数据库断数据源的信息。

如果数据存储在数据库中,那么,即使客户端使用动态Web内容,比如applet,我们依旧需要执行服务器端处理。

想象以下,如果一个搜索引擎网站完全使用applet,那么用户将会看到:“正在下载50TB的applet,请等待!”。

显然,这样很愚蠢;这种情况下,我们需要与数据库进行会话。

从客户端到Web层再到数据库(三层结构),要比从applet直接到数据库(二层结构)更灵活,也更安全,而性能上的损失很少甚至没有。

毕竟数据库调用通常是对速度影响最大的步骤,因而,经过中间层可以执行高速缓存和连接共享。

理论上讲,servelt并非只用于处理HTTP请求的Web服务器或应用服务器,它同样可以用于其他类型的服务器。

例如,servlet能够嵌入到FTP或邮件服务器中,扩展他们的功能。

而且,用于会话启动协议服务器的servlet API最近已经被标准化(参见/en/jsr/detail?id=116)。

但在实践中,servelt的这种用法尚不流行,在此,我们只论述HTTP Servlet。

1.3 Servlet相对于“传统”CGI的优点和传统CGI及许多类CGI技术相比,Java servelt效率更高、更易用、更强大、更容易移植、更安全、也更廉价。

1、效率应用传统的CGI,针对每个HTTP请求都用启动一个新的进程。

如果CGI程序自身相对比较简短,那么启动进程的开销会占用大部分执行时间。

而使用servelt,Java 虚拟机会一直运行,并用轻量级的Java线程处理每个请求,而非重量级的操作系统进程。

类似地,应用传统的CGI技术,如果存在对同一CGI程序的N个请求,那么CGI程序的代码会载入内存N次。

同样的情况,如果使用servlet则启动N个线程,单仅仅载入servlet类的单一副本。

这种方式减少了服务器的内存需求,通过实例化更少的对象从而节省了时间。

最后,当CGI程序结束对请求的处理之后,程序结束。

这种方式难以缓存计算结果,保持数据库连接打开,或是执行依靠持续性数据的其他优化。

然而,servelt会一直停留在内存中(即使请求处理完毕),因而可以直接存储客户请求之间的任意复杂数据。

2、便利Servelt提供大量的基础构造,可以自动分析和解码HTML的表单数据,读取和设置HTTP报头,处理cookie,跟踪会话,以及其他次类高级功能。

而在CGI中,大部分工作都需要我们资金完成。

另外,如果您已经了解了Java编程语言,为什么还有学校Perl呢?您已经承认应用Java技术编写的代码要比Visual Basic,VBScript 或C++编写的代码更可靠,且更易重用,为什么还有倒退回去选择那些语言来开发服务器端的程序呢?3、强大Servlet支持常规CGI难以实现或根本不能实现的几项功能。

Servlet能够直接于Web服务器对话,而常规的CGI程序做不到这一点,至少在不使用服务器专有API 的情况下是这样。

例如,与Web服务器的通信使得讲相对URL转换成具体的路径名变得更为容易。

多个servelt还可以共享数据,从而易于实现数据库连接共享和类似的资源共享优化。

Servelt还能维护请求之间的信息,使得诸如会话跟踪和计算结果缓存等技术变得更为简单。

4、可移植性Servelt使用Java编程语言,并且遵循标准的API。

所有主要的Web服务器。

实际上都直接或通过插件支持servlet。

因此。

为Macromedia JRun编写的servlet,可以不经过任何修改地在Apache Tomcat,Microsoft Internet Information Server,IBM WebSphere 。

iPlanet Enterprise Server。

Oracle9i AS 或者StrNine WebStar 上运行。

他们是java2平台企业版的一部分,所以对servlet的支持越来越普遍。

5、廉价对于开发用的网站、低容量或中等容量网站的部署,有大量免费或极为廉价的Web服务器可供选择。

因此,通过使用servelt和jsp,我们可以从免费或廉价的服务器开始,在项目获得初步成功后,在移植到更高性能或高级管理工具的昂贵的服务器上。

这与其他CGI方案形成鲜明的对比,这些CGI方案在初期都需要为购买专利软件包投入大量的资金。

价格和可移植性在某种程度上是相互关联的。

例如,Marty记录了所有通过电子邮件向他发送问题的读者的所在国。

印度接近列表的顶端,可能仅次于美国。

Marty 曾在马尼拉讲授过jsp和servlet培训课程,那儿对servelt和jsp技术抱很大的兴趣。

那么,为什么印度和菲律宾都对这项技术着呢感兴趣呢?我们推测答案可能分两部分。

首先,这两个国家都拥有大量训练有素的软件开发人员。

其次,这两个国家的货币对美元的汇率都极为不利。

因此,从美国公司那里购买专用Web服务器会消耗掉项目的大部分前期资金。

但是,使用servlet 和JSP,他们能够从免费的服务器开始:Apache Tomcat。

项目取得成功之后,他们可以转移到性能更高、管理更容易,但需要付费的服务器。

他们的servelt和jsp不需要重写编写。

如果他们的项目变得更庞大,他们或许希望转移到分布式环境。

没有问题:他们可以转而使用Macromedia JRun Professional,该服务器支持分布式应用。

同样,他们的servelt和jsp没有任何部分需要重写。

如果项目变得极为庞大,错综复杂,他们或许希望使用Enterprise JavaBeans来封装他们的商业逻辑。

因此,他们可以切换到BEA WebLogic或Oracle9i AS。

同样,不需要对servlet和jsp做出更改。

最后,如果他们的项目变得更庞大,他们或许将他从Linux转移到运行IBM WebSphere的IBM大型机上。

他们还是不需要做出任何更改。

6、安全传统CGI程序中主要的漏洞来源之一就是,CGI程序常常由通过的操作系统外壳来执行。

因此,CGI程序必须仔细地过滤掉那些可能被外壳特殊处理的字符,如反引导和分号。

实现这项预防措施的难度可能超出我们的想象,在广泛应用的CGI库中,不断发现由这类问题引发的弱点。

问题的第二个来源是,一些CGI程序用不自动检查数组和字符串边界的语言编写而成。

例如,在C和C++中,可以分配一个100个元素的数组,然后向第999个“元素“写入数据——实际上是程序内存的随机部分,这完全合法。

因而,如果程序员忘记执行这项检查,就会将系统暴露在蓄意或偶然的缓冲区溢出攻击之下。

Servelt不存在这些问题。

即使servelt执行系统调用激活本地操作系统上的程序,它也不会用到外壳来完成这项任务。

相关文档
最新文档