外文文献及翻译(共13页).docx

上传人:飞****2 文档编号:16645682 上传时间:2022-05-18 格式:DOCX 页数:13 大小:31.72KB
返回 下载 相关 举报
外文文献及翻译(共13页).docx_第1页
第1页 / 共13页
外文文献及翻译(共13页).docx_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《外文文献及翻译(共13页).docx》由会员分享,可在线阅读,更多相关《外文文献及翻译(共13页).docx(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上文献翻译原文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 wh

2、ich 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

3、 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 e

4、asy 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 th

5、e 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,

6、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 dynami

7、c 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 fr

8、om 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 clients request, call

9、ing 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 / doPost / doHead) and generate a response. Although such a complex, in fact, simply said to Servlet is a Java class. And the general cat

10、egory 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 databa

11、se 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 loo

12、ks 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 fil

13、es 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.

14、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

15、engine of this type loading, handling requests from customers, and the results returned to the customer. After 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

16、 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

17、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 fo

18、r the roles of Model, View and Controller.Servlets, Filters, and Listeners A servlet is a Java class that extends a server with functionality for processing a request and producing a response. Its implemented using the classes and interfaces defined by the Servlet API. The API consists of two packag

19、es: 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 directl

20、y or by extending one of the support classes. This interface defines the methods used by the web container to manage and interact with the servlet. A servlet for processing HTTP requests typically extends the javax.servlet.http.HttpServlet class. This class implements the Servlet interface and provi

21、des additional methods suitable for HTTP processing. Servlet LifecycleThe web container manages all aspects of the servlets 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

22、 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 dont implement these methods;

23、the HttpServlet class already takes care of HEAD, OPTIONS, and TRACE requests in a way thats suitable for most servlets, and the DELETE and PUT HTTP methods are rarely used in a web application. Its important to realize that the container creates only one instance of each servlet. This means that th

24、e 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( ) a

25、nd 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 cont

26、ainers. 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 inter

27、face. 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

28、 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

29、the Servlet 2.3 specification, so if youre using a container that doesnt yet support this version of the specification, Im afraid youre out 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 its sent to

30、 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 trans

31、formations. 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

32、 or having the same extension.Listeners Listeners 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 session

33、attribute(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 passivatio

34、n events (used by a container that temporarily saves session state to disk or migrates a session to another server). A new session 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 ea

35、ch 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

36、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 cre

37、ate 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 part

38、s 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

39、 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 the pages are pure controller and business logic processing, it accesses a database to authenticate us

40、ers, 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.

41、 Its 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. Lets look at the main requirements and see how we can map them to

42、 appropriate component types:l Database access should be abstracted, to avoid knowledge of a specific data schema or database engine in more than one part of the application: beans in the role of Model can be used to accomplish this.l The database access beans must be made available to all other par

43、ts of the application when it starts: an application lifecycle event listener is the perfect component type for this task. l Only authenticated users must be allowed to use the application: a filter can perform access control to satisfy this requirement. l Request processing is best done with Java c

44、ode: a servlet, acting as the Controller, fits the bill. l It must be easy to change the presentation: this is where JSP shines, acting as the View. 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

45、 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 r

46、esponse 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 valid

47、ation, 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: l All requests for processing must be passed to the single Controller servlet.l The servlet must be able t

48、o 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: l A strategy for extending the application to support new types of processing requests in a flexible manner.l A mechanism for ch

49、anging the page flow of the application without modifying code.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, youre 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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁