首页 基于JSP实现的餐饮管理系统毕业设计英文文献翻译

基于JSP实现的餐饮管理系统毕业设计英文文献翻译

举报
开通vip

基于JSP实现的餐饮管理系统毕业设计英文文献翻译基于JSP实现的餐饮管理系统毕业设计英文文献翻译 项目说明书 英文文献及中文翻译 班 级: 学号: 姓 名: 学 院: 专 业: 指导教师: 2014 年 6 月 Overview of JSP Technology and JSP application frameworks 1.Benefits of JSP JSP pages are translated into servlets. So, fundamentally, any task JSP pages can perform c...

基于JSP实现的餐饮管理系统毕业设计英文文献翻译
基于JSP实现的餐饮管理系统毕业 设计 领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计 英文文献翻译 项目说明书 英文文献及中文翻译 班 级: 学号: 姓 名: 学 院: 专 业: 指导教师: 2014 年 6 月 Overview of JSP Technology and JSP application frameworks 1.Benefits of JSP JSP pages are translated into servlets. So, fundamentally, any task JSP pages can perform could also be accomplished by servlets. However, this underlying equivalence does not mean that servlets and JSP pages are equally appropriate in all scenarios. The issue is not the power of the technology, it is the convenience, productivity, and maintainability of one or the other. After all, anything you can do on a particular computer platform in the Java programming language you could also do in assembly language. But it still matters which you choose.JSP provides the following benefits over servlets alone: • It is easier to write and maintain the HTML. Your static code is ordinary HTML: no extra backslashes, no double quotes, and no lurking Java syntax. • You can use standard Web-site development tools. Even HTML tools that know nothing about JSP can be used because they simply ignore the JSP tags. • You can divide up your development team. The Java programmers can work on the dynamic code. The Web developers can concentrate on the presentation layer. On large projects, this division is very important. Depending on the size of your team and the complexity of your project, you can enforce a weaker or stronger separation between the static HTML and the dynamic content. Now, this discussion is not to say that you should stop using servlets and use only JSP instead. By no means. Almost all projects will use both. For some requests in your project, you will use servlets. For others, you will use JSP. For still others, you will combine them with the MVC architecture . You want the appropriate tool for the job, and servlets, by themselves, do not complete your toolkit. 2.Advantages of JSP Over Competing Technologies A number of years ago, Marty was invited to attend a small 20-person industry roundtable discussion on software technology. Sitting in the seat next to Marty was James Gosling, inventor of the Java programming language. Sitting several seats away was a high-level manager from a very large software company in Redmond, Washington. During the discussion, the moderator brought up the subject of Jini, which at that time was a new Java technology. The moderator asked the manager what he thought of it, and the manager responded that it was too early to tell, but that it seemed to be an excellent idea. He went on to say that they would keep an eye on it, and if it seemed to be catching on, they would follow his company's usual "embrace and extend" strategy. At this point, Gosling lightheartedly interjected "You mean disgrace and distend." Now, the grievance that Gosling was airing was that he felt that this company would take technology from other companies and suborn it for their own purposes. But guess what? The shoe is on the other foot here. The Java community did not invent the idea of designing pages as a mixture of static HTML and dynamic code marked with special tags. For example, ColdFusion did it years earlier. Even ASP (a product from the very software company of the aforementioned manager) popularized this approach before JSP came along and decided to jump on the bandwagon. In fact, JSP not only adopted the general idea, it even used many of the same special tags as ASP did..So, the question becomes: why use JSP instead of one of these other technologies? Our first response is that we are not arguing that everyone should. Several of those other technologies are quite good and are reasonable options in some situations. In other situations, however, JSP is clearly better. Here are a few of the reasons. 2.1 Versus .NET and Active Server Pages (ASP) . NET is well-designed technology from Microsoft. ASP.NET is the part that directly competes with servlets and JSP. The advantages of JSP are two fold.First, JSP is portable to multiple operating systems and Web servers; you aren't locked into deploying on Windows and IIS. Although the core .NET platform runs on a few non-Windows platforms, the ASP part does not. You cannot expect to deploy serious ASP.NET applications on multiple servers and operating systems. For some applications, this difference does not matter. For others, it matters greatly.Second, for some applications the choice of the underlying language matters greatly. For example, although .NET's C# language is very well designed and is similar to Java, fewer programmers are familiar with either the core C# syntax or the many auxiliary libraries. In addition, many developers still use the original version of ASP. With this version, JSP has a clear advantage for the dynamic code. With JSP, the dynamic part is written in Java, not VBScript or another ASP-specific language, so JSP is more powerful and better suited to complex applications that require reusable components. You could make the same argument when comparing JSP to the previous version of ColdFusion; with JSP you can use Java for the "real code" and are not tied to a particular server product. However, the current release of ColdFusion is within the context of a J2EE server, allowing developers to easily mix ColdFusion and servlet/JSP code. 2.2 Versus PHP PHP (a recursive acronym for "PHP: Hypertext Preprocessor") is a free, open-source, HTML-embedded scripting language that is somewhat similar to both ASP and JSP. One advantage of JSP is that the dynamic part is written in Java, which already has an extensive API for networking, database access, distributed objects, and the like, whereas PHP requires learning an entirely new, less widely used language. A second advantage is that JSP is much more widely supported by tool and server vendors than is PHP. 2.3 Versus Pure Servlets JSP doesn't provide any capabilities that couldn't, in principle, be accomplished with servlets. In fact, JSP documents are automatically translated into servlets behind the scenes. But it is more convenient to write (and to modify!) regular HTML than to use a zillion println statements to generate the HTML. Plus, by separating the presentation from the content, you can put different people on different tasks: your Web page design experts can build the HTML by using familiar tools and either leave places for your servlet programmers to insert the dynamic content or invoke the dynamic content indirectly by means of XML tags. Does this mean that you can just learn JSP and forget about servlets? Absolutely not! JSP developers need to know servlets for four reasons: 1. JSP pages get translated into servlets. You can't understand how JSP works without understanding servlets. 2. JSP consists of static HTML, special-purpose JSP tags, and Java code. What kind of Java code? Servlet code! You can't write that code if you don't understand servlet programming. 3. Some tasks are better accomplished by servlets than by JSP. JSP is good at generating pages that consist of large sections of fairly well structured HTML or other character data. Servlets are better for generating binary data, building pages with highly variable structure, and performing tasks (such as redirection) that involve little or no output. 4. Some tasks are better accomplished by a combination of servlets and JSP than by either servlets or JSP alone. 2.4 Versus JavaScript JavaScript, which is completely distinct from the Java programming language, is normally used to dynamically generate HTML on the client, building parts of the Web page as the browser loads the document. This is a useful capability and does not normally overlap with the capabilities of JSP (which runs only on the server). JSP pages still include SCRIPT tags for JavaScript, just as normal HTML pages do. In fact, JSP can even be used to dynamically generate the JavaScript that will be sent to the client. So, JavaScript is not a competing technology; it is a complementary one. It is also possible to use JavaScript on the server, most notably on Sun ONE (formerly iPlanet), IIS, and BroadVision servers. However, Java is more powerful, flexible, reliable, and portable. 2.5 Versus WebMacro or Velocity JSP is by no means perfect. Many people have pointed out features that could be improved. This is a good thing, and one of the advantages of JSP is that the specification is controlled by a community that draws from many different companies. So, the technology can incorporate improvements in successive releases. However, some groups have developed alternative Java-based technologies to try to address these deficiencies. This, in our judgment, is a mistake. Using a third-party tool like Apache Struts that augments JSP and servlet technology is a good idea when that tool adds sufficient benefit to compensate for the additional complexity. But using a nonstandard tool that tries to replace JSP is a bad idea. When choosing a technology, you need to weigh many factors: standardization, portability, integration, industry support, and technical features. The arguments for JSP alternatives have focused almost exclusively on the technical features part. But portability, standardization, and integration are also very important. For example, the servlet and JSP specifications define a standard directory structure for Web applications and provide standard files (.war files) for deploying Web applications. All JSP-compatible servers must support these standards. Filters can be set up to apply to any number of servlets or JSP pages, but not to nonstandard resources. The same goes for Web application security settings. Besides, the tremendous industry support for JSP and servlet technology results in improvements that mitigate many of the criticisms of JSP. For example, the JSP Standard Tag Library and the JSP 2.0 expression language address two of the most well-founded criticisms: the lack of good iteration constructs and the difficulty of accessing dynamic results without using either explicit Java code or verbose jsp:useBean elements. 3. Misconceptions About JSP Forgetting JSP Is Server-Side Technology Here are some typical questions Marty has received (most of them repeatedly). • Our server is running JDK 1.4. So, how do I put a Swing component in a JSP page? • How do I put an image into a JSP page? I do not know the proper Java I/O commands to read image files. • Since Tomcat does not support JavaScript, how do I make images that are highlighted when the user moves the mouse over them? • Our clients use older browsers that do not understand JSP. What should we do? • When our clients use "View Source" in a browser, how can I prevent them from seeing the JSP tags? All of these questions are based upon the assumption that browsers know something about the server-side process. But they do not. Thus: • For putting applets with Swing components into Web pages, what matters is the browser's Java version—the server's version is irrelevant. If the browser supports the Java 2 platform, you use the normal APPLET (or Java plug-in) tag and would do so even if you were using non-Java technology on the server. • You do not need Java I/O to read image files; you just put the image in the directory for Web resources (i.e., two levels up from WEB-INF/classes) and output a normal IMG tag. • You create images that change under the mouse by using client-side JavaScript, referenced with the SCRIPT tag; this does not change just because the server is using JSP. • Browsers do not "support" JSP at all—they merely see the output of the JSP page. So, make sure your JSP outputs HTML compatible with the browser, just as you would do with static HTML pages. • And, of course you need not do anything to prevent clients from seeing JSP tags; those tags are processed on the server and are not part of the output that is sent to the client. Confusing Translation Time with Request Time A JSP page is converted into a servlet. The servlet is compiled, loaded into the server's memory, initialized, and executed. But which step happens when? To answer that question, remember two points: • The JSP page is translated into a servlet and compiled only the first time it is accessed after having been modified. • Loading into memory, initialization, and execution follow the normal rules for servlets. The most frequently misunderstood entries are highlighted. When referring to the table, note that servlets resulting from JSP pages use the _jspService method (called for both GET and POST requests), not doGet or doPost. Also, for initialization, they use the jspInit method, not the init method.JSP page translated into servlet Servlet compiled Servlet loaded into server's memory jspInit called _jspService called. 4.What are application frameworks: A framework is a reusable, semi-complete application that can be specialized to produce 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 provide semi-complete versions of a subsystem that can be specialized to provide a custom component. 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 the Internet 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 seven 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 and videos. 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. 5. Java servlets: Sun’s Java Servlet platform directly addresses the two main drawbacks of CGI programs.First, servlets offer better performance and utilization of resources than conventional 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]. 6. 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("

One line of HTML.

"); out.println("

Another line of HTML.

"); 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. 7. 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 state 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. The first character in the property name must be uppercase. The return value will always 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 be public boolean isOn() The canonical method signatures play an important role when working with Java- Beans. Other components are able to use the Java Reflection 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. A substantial custom tag library is bundled with the framework to make Struts easy to use with 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技术概述与应用框架 1. JSP的好处 JSP页面最终会转换成servlets。因而,从根本上,JSP页面能够执行的任何 任务都可以用servlets来完成。然而,这种底层的等同性并不意味着servlets和 JSP页面对于所有的情况都等同适用。问题不在于技术的能力,而是二者在便利 性、生产率和可维护性上的不同。毕竟,在特定平台上能够用Java编程语言完 成的事情,同样可以用汇编语言来完成,但是选择哪种语言依旧十分重要。 和单独使用servlets相比,JSP提供下述好处: ?JSP中HTML的编写与维护更为简单。JSP中可以使用常规的HTML:没有额 外的反斜杠,没有额外的双引号,也没有暗含的Java语法。 ?能够使用 标准 excel标准偏差excel标准偏差函数exl标准差函数国标检验抽样标准表免费下载红头文件格式标准下载 的网站开发工具。即使对那些对JSP一无所知的HTML工具,我们也可以使用,因为它们会忽略JSP标签(JSP tags)。 ?可以对开发团队进行划分。Java程序员可以致力于动态代码。Web开发人员可以将经理集中在表示层(presentation layer)上。对于大型的项目,这种划分极为重要。依据开发团队的大小,及项目的复杂程度,可以对静态HTML和动态内容进行弱分离(weaker separation)和强分离(stronger separation)。 在此,这个讨论并不是让您停止使用servlets,只使用JSP。几乎所有的项目都会同时用到这两种技术。针对项目中的某些请求,您可能会在MVC构架下组合使用这两项技术。我们总是希望用适当的工具完成相对应的工作,仅仅是servlet并不能填满您的工具箱。 2. JSP相对于竞争技术的优势 许多年前,Marty受到邀请,参加一个有关软件技术的小型(20个人)研讨会。做在Marty旁边的人是James Gosling--- Java编程语言的发明者。隔几个位置,是来自华盛顿一家大型软件公司的高级经理。在讨论过程中,研讨会的主席提出了Jini的议题,这在当时是一项新的Java技术。主席向该经理询问他的想法。他继续说,他们会持续关注这项技术,如果这项技术变得流行起来,他们会遵循公司的“接受并扩充(embrace and extend)”的策略。此时, Gosling随意地插话说“你的意思其实就是不接受且不扩充(disgrace and distend)。” 在此, Gosling的抱怨显示出,他感到这个公司会从其他公司那里拿走技术,用于他们自己的目的。但你猜这次怎么样,这次鞋子穿在了另一只脚上。Java社团没有发明这一思想----将页面设计成由静态HTML和用特殊标签标记的动态代码混合组成。ColdFusion多年前就已经这样做了。甚至ASP(来自于前述经理所在公司的一项产品)都在JSP出现之前推广了这种方式。实际上,JSP不只采用了这种通用概念,它甚至使用许多和ASP相同的特殊标签。 因此,问题变成:为什么使用JSP,而不使用其他技术呢,我们的第一反应是我们不是在争论所有的人应该做什么。其他这些技术中,有一些也很不错,在某些情况下也的确是合情合理的选择。然而,在其他情形中,JSP明显要更好一些。下面给出几个理由。 2.1 与.NET和Active Server Pages (ASP)相比 .NET是Microsoft精心设计的一项技术。ASP.NET是与servlets和JSP直接竞争的技术。JSP的优势体现在两个方面。首先,JSP可以移植到多种操作系统和Web服务器,您不必仅仅局限于部署在Windows 和IIS上尽管核心.NET平台可以在好几种非Windows平台上运行,但ASP这一部分不可以。您不能期望可以将重要的ASP.NET应用部署到多种服务器和操作系统。对于某些应用,这种差异没有什么影响。但有些应用,这种差异却非常重要。其次,对于某些应用,底层语言的选择至关重要。例如,尽管.NET的C#语言设计优良,且和Java类似,但熟悉核心C#语法和众多工具库的程序员很少。此外,许多开发者依旧使用最初版本的ASP。相对于这个版本,JSP在动态代码方面拥有明显的优势。使用JSP,动态部分是用Java编写的,而非VBScript过其他ASP专有的语言,因此JSP更为强劲,更适合于要求组件重用的复杂应用。 当将JSP与之前版本的ColdFusion对比时,您可能会得到相同的结论。应用JSP,您可以使用Java编写“真正的代码”,不必依赖于特定的服务器产品。然而,当前版本的ColdFusion满足J2EE服务器的环境,允许开发者容易的混合使用ColdFusion和Servlet/JSP代码。 2.2 与PHP相比 PHP(“PHP:Hypertext Preprocessor”的递归字母缩写词)是免费的、开放源代码的、HTML嵌入其中的脚本语言,与ASP和JSP都有某种程度的类似。JSP的一项优势是动态部分用Java编写,而Java已经在联网、数据库访问、分布式对象等方面拥有广泛的API,而PHP需要学习全新的、应用相对广泛的语言。JSP的第二项优势是,和PHP相比,JSP拥有极为广泛的工具和服务器提供商的支持。 2.3 与纯Servlet相比 原则上,JSP并没有提供Servlet不能完成的功能。实际上,JSP文档在后台被自动转换成Servlet。但是编写(和修改)常规的HTML,要比无数println语句生成HTML要方便得多。另外,通过将表示与内容分离,可以为不同的人分配不同的任务:网页设计人员使用熟悉的工具构建HTML,要么为Servlet程序员留出空间插入动态内容,要么通过XML标签间接调用动态内容。这是否表示 您只可以学习JSP,将Servlet丢到一边呢,当然不是~由于以下4种原因,JSP开发人员需要了解Servlet: (1)JSP页面会转换成Servlet。不了解Servlet就无法知道JSP如何工作。 (2)JSP由静态HTML、专用的JSP标签和Java代码组成。哪种类型的Java代码呢,当然是Servlet代码~如果不了解Servlet编程,那么就无法编写这种代码。 (3)一些任务用Servlet完成比用JSP来完成要好。JSP擅长生成由大量组织有序的结构化HTML或其他字符数据组成的页面。Servlet擅长生成二进制数据,构建结构多样的页面,以及执行输出很少或者没有输出的任务(比如重定向)。 (4)有些任务更适合于组合使用Servlet和JSP来完成,而非单独使用Servlet或JSP。 2.4 与JavaScript相比 JavaScript和Java编程语言完全是两码事,前者一般用于在客户端动态生成HTML,在浏览器载入文档时构建网页的部分内容。这是一项有用的功能,一般与JSP的功能(只在服务器端运行)并不发生重叠。和常规HTML页面一样,JSP页面依旧可以包括用于JavaScript的SCRIPT标签。实际上,JSP甚至能够用来动态生成发送到客户端的JavaScript。因此,JavaScript不是一项竞争技术,它是一项补充技术。 JavaScript也可以用在服务器端,最因人注意的是SUN ONE(以前的iPlanet)、IIS和BroadVision服务器。然而,Java更为强大灵活、可靠且可移植。 2.5 与WebMacro和Velocity相比 JSP决非完美。许多人都曾指出过JSP中能够改进的功能。这是一件好事,JSP的优势之一是该 规范 编程规范下载gsp规范下载钢格栅规范下载警徽规范下载建设厅规范下载 由许多不同公司组成的社团控制。因此,在后续版本中,这项技术能够得到协调的改进。 但是,一些组织已经开发出了基于Java的替代技术,试图弥补这些不足。据我们的判断,这样做是错误的。使用扩充JSP和Servlet技术的第三方工具,如Apache Structs,是一种很好的思路,只要该工具带来的好处能够补偿工具带来的额外复杂性。但是,试图使用非标准的工具代替JSP则不理想。在选择一项技术时,需要权衡许多方面的因素:标准化、可移植性、集成性、行业支持和技术特性。对于JSP替代技术的争论几乎只是集中在技术特性上,而可移植性、标准化和集成性也十分重要。例如,Servlet和JSP规范为Web应用定义了一个标 准的目录结构,并提供用于部署Web应用的标准文件(.war文件)。所有JSP兼容的服务器必须支持这些标准。我们可以建立过滤器作用到任意树木的Servlet和JSP页面上,但不能用于非标准资源。Web应用安全设置也同样如此。 此外,业界对JSP和Servlet技术的巨大支持使得这两项技术都有了巨大的进步,从而减轻了对JSP的许多批评。例如,JSP标准标签库和JSP 2.0表达式语言解决了两种最广泛的批评:缺乏良好的迭代结构;不使用显式的Java代码或冗长的jsp:useBean元素难以访问动态结果。 3. 对JSP的误解 忘记JSP技术是服务器端技术。 下面是Marty收到的一些典型问题(大部分问题不止一次的出现)。 ?我们的服务器正在运行JDK1.4。我如何将Swing组件用到JSP页面呢, ?我如何将图像放到JSP页面中,我不知道读取图像文件应该使用哪些JavaI/O命令。 ?Tomcat不支持JavaScript,当用户在图像上移动鼠标时,我如何使图像突出显示呢, ?我们的客户使用不理解JSP的旧浏览器。我应该怎么做, ? 当我们的客户在浏览器中使用“View Source”(查看源代码)时,如何阻止他们看到JSP标签, 所有这些问题都基于浏览器对服务器端的过程在有所了解的假定之上。但事实上浏览器并不了解服务器端的过程。因此: ?如果要将使用Swing组件的applet放到网页中,重要的是浏览器的Java版本,和服务器的Java版本无关。如果浏览器支持Java 2平台,您可以使用正常的APPLET(或Java插件)标签,即使在服务器上使用了非Java技术也须如此。 ?您不需要Java I/O来读取图像文件,您只需将图像放在存储Web资源的目录中(即WEB-INF/classes向上两级的目录),并输出一个正常的IMG标签。 ?您应该用SCRIPT标签,使用客户端JavaScript创建在鼠标下会更改的图像,这不会由于服务器使用JSP而改变。 ?浏览器根本不“支持”JSP----它们看到的只是JSP页面的输出。因此,如同对待静态HTML页面一样,只需确保JSP输出的HTML与浏览器兼容。 ?当然,您不需要采取什么措施来阻止客户看到JSP标签,这些标签在服务器上进行处理,发送给客户的输出中并不出现。 混淆转换期间和请求期间 ?JSP页面需要转换成servlet。Servlet在编译后,载入到服务器的内容中,初始化并执行。但是每一步发生在什么时候呢,要回答这个问题,要记住以下两点: ?JSP页面仅在修改后第一次被访问时,才会被转换成servlet并进行编译;载入到内存中、初始化和执行遵循servlet的一般规则。 最常被误解的项已经突出标示出来。在参考该表时,要注意,由JSP页面生成的servlet使用_jspService方法(GET和POST请求都调用该函数),不是doGet或doPost方法。同样,对于初始化,它们使用jspInit方法,而非init方法。将JSP 页面转换成servlet 编译Servlet 将Servlet 载入到服务器内存中调用jspInit调用_jspService。 4. 什么是应用框架: 框架(framework)是可重用的,半成品的应用程序,可以用来产生专门的定制程序。像人一样,软件应用的相似性比不同点要多。它们运行在相似的机器上,期望从相同的设备输入信息,输出到相同的显示设备,并且将数据存储到相同的硬盘设备。开发传统桌面应用的开发人员更习惯于那些可以涵盖应用开发同一性的工具包和开发环境。构架在这些公共基础上的应用框架可以为开发人员提供可以为他们的产品提供可重用服务的基础架构。 框架向开发人员提供一系列具有以下特征的骨架组件: 1(已经知道它们在其它程序上工作得很好; (它们随时可以在下一个项目中使用; 2 3(它们可以被组织的其它团队使用。 对于框架是典型的构建还是购买命题。如果你自己构建它,在你完成时你就会理解它,但是在你被融入之前又将花费多长时间呢,如果要购买,你必须得克服学习曲线,同样,在你可以用它进行工作之前又得花多长时间,这里没有所谓正确答案,但许多观察者都会同意,像Struts这样的框架能提供比从头开始开发更显著的投资回报,特别是对于大型项目来说。 其它类型的框架: 框架的概念不仅用于应用程序也可用于组件。在其它的资料里面,我们也介绍了一些可以和Struts一起使用的框架。这些包括Lucene搜索引擎,Scaffold工具包,Struts验证器,以及Tiles标签库。与应用框架一样,这些工具也提供了一些半完成的版本,可以用在用户的定制组件之中。某些框架被限制于专门的开发环境中。Struts以及本文中涉及的组件却不是这样。你可以在很多环境中来开发Struts:Visual Age for Java,JBuilder, Ecli,pse,Emacs,甚至使用Textpad。对于你的工具,如果你可以用来开发Java,你就可以用它来开发Struts。 使用的技术: 使用Struts的应用开发使用了大量的其他基础技术。这些技术并不是专门针对Struts,而是所有Java web 应用都可以使用的。开发者使用Struts之类的框架是为了隐藏在诸如HTTP,CGI,以及JSP之类技术后面的繁琐的细节。作为一个Struts开发者,你并不需要知晓所有的相关知识,但是这些基本技术的工作原理可能有助于你针对棘手问题设计出创造性的 方案 气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载 。 超文本传输协议 (HTTP): 当两个国家之间进行调解时,外交官们总是遵循一定的正式协议。外交协议主要设计来避免误解,以及防止谈判破裂。同样,当计算机间需要对话,它们也遵循一个正式的协议。这个协议定义数据是如何传输,以及它们到达后如何进行解码。Web应用程序就是使用HTTP协议在运行浏览器的计算机和运行的服务器的程序间传输数据。 很多服务器应用程序使用HTTP之外的其他协议。他们在计算机之间维护一个持久性的连接。应用服务器可以清楚的知道是谁连接上来,而且何时中断连接。因为它们知道每一个连接的状态,以及每一个使用它的人。这称之为状态协议。 相反, HTTP是一个无状态协议。HTTP Server 可以接受来自于各种客户的各种请求,并提供各种响应,即使是这个响应仅仅是说No。没有大量的协商和连接持久性,无状态协议可以处理大量的请求。这也是Internet 可以扩展到很多计算机的原因。 HTTP 成为通用标准的原因是其简单性。HTTP请求看起来就像一个平常的文本文档。这使应用程序很容易创建HTTP请求。你甚至可以通过标准的程序如 Telnet来手动传递一个HTTP请求。当HTTP响应返回时,它也是一个开发者可以直接阅读的平面文本。HTTP请求的第一行包含方法,其后是请求的来源地址和HTTP版本。HTTP请求头跟在首行后面,可以没有也可以有多个。HTTP头向服务器提供额外的信息。可以包括浏览器的种类和版本,可接受的文档类型,浏览器的cookies等等。7 种请求方法中, GET和 POST是用得最多的。 一旦服务器接收到请求,它就要产生一个HTTP响应。响应的第一行称为状态行,包含了HTTP协议的版本,数字型状态,以及状态的简短描述。状态行后,服务器将返回一个HTTP响应头,类似于HTTP请求头。如上所述,HTTP并不在请求间保持状态信息。服务器接受请求,发出响应,并且继续愉快地处理文本请求。 因为简单和效率,无状态协议不适合于需要跟踪用户状态的动态应用。Cookies和 URL 重写是两个在请求间跟踪用户状态的方式。cookie是一种特殊的信息包,存储于用户的计算机中。URL重写是在页面地址中存储一个特殊的标记,Java服务器可以用它来跟踪用户。这两种方法都不是无缝的,是用哪一个都意味着在开发时都要进行额外的工作。对其本身来说,标准的HTTP web服务器并不传输动态内容。它主要是使用请求来定位文件资源,并在响应中返回此资源。通常这里的文件使用Hypertext Markup Language (HTML) [W3C,HTML] 格式化,以使浏览器可以显示它们。HTML页面通常包含一些到其他页面的超文本连接,也可以显示其他一些内容比如图像和视频等等。用户点击连接将产生另一个请求,就开始一个新的处理过程。标准web服务器处理静态内容处理得很好,但处理动态内容时则需要额外的帮助手段了。 定义: 静态内容直接来自于文本或数据文件,比如HTML或者 JPEG文件。这些文件可以随时改变,但通过浏览器请求时,却不能自动改变。相反,动态内容是临时产生的,典型地,它是针对浏览器的个别请求的响应。 公共网关接口(CGI): 第一个普遍用来产生动态内容的标准是通用网关接口(Common Gateway Interface (CGI))。CGI使用标准的操作系统特征,比如环境变量和标准输入输出,在Web服务器间以及和主机系统间创建桥接和网关。其他程序可以看到web server传递过来的请求,并创建一个定制的响应。当web服务器接收到一个对CGI程序的请求时,它便运行这个程序并向其提供它请求里面所包含的信息。CGI程序运行,并将输出返回给Web server,web server 则将输出响应给浏览器。CGI定义了一套关于什么信息将作为环境变量传递,以及它希望怎样使用标准输入和输出的惯例。与HTTP一样,CGI是灵活和易于实现的,并且已经有大量现成的CGI程序。 CGI的主要缺点是它必须为每个请求运行一个程序。这是一个相对昂贵的处理方法,对大容量站点来说,每分钟有数千个请求,有可能使站点瘫痪。CGI程序的另一个缺点是平台依赖性,一个平台上开发的程序不一定在另一个平台上能运行。 5.Java servlet: Sun公司的Java Servlet平台直接解决了CGI程序的两个主要缺点: 首先,servlet 比常规CGI 程序提供更好的性能和资源利用。其次,一次编写,随处运行的JAVA特性意味着servlet在有JVM 的操作系统间是轻便的可移动的。Servlet看起来好像是一个微小的web server。它接受请求并产生响应。但和常规web server不同,servlet API 是专门设计来帮助Java 开发人员创建动态应用的。 Servlet 本身是要编译成字节码的Java类,就像其他Java对象一样。Servlet访问HTTP 特定服务的API,但它仍然是一个运行于程序之中的Java 对象,并可以利用所有的Java 资产。为了使常规web servers能访问servlet,servlet被安插在一个容器之中。Servlet容器连接到Web服务器。每servlet 都可以声明它可以处理何种样式的URL。当符合所注册样式的请求到达,web server将请求传递给容器,容器则调用响应的servlet。但和CGI 程序不同,并不是针对每个请求都要创建一个新的servlet。一旦容器实例化了一个servlet,它就仅为每个新的请求创建一个新的线程。Java线程可比使用CGI程序的服务器处理开销小多了。 一旦servlet被创建,使用它处理额外的请求仅带来很小的额外开销。Servlet开发人员可以使用init() 方法保持对昂贵资源的引用,比如到数据库或者EJB Home接口的连接,以便它们可以在不同的请求之间进行共享。获得这些资源要耗费数秒时间,这比大多数冲浪者愿意等的时间要长些。 Servlet的另一个好处是,它是多线程的,servlet开发人员必须特别注意确保它们的servlet是线程安全的。学习servlet 编程,我们推荐Java Servlets by Example, 作者Alan R. Williamson[Williamson]。 6.JavaServer Pages: 虽然servlets对CGI程序来说前进了一大步,但它也不是万能灵药。为了产生响应,开发人员不得不使用大量的println语句来生成HTML。比如这样的代码: out.println("

One line of HTML.

"); out.println("

Another line of HTML.

"); 在产生HTTP响应的Servlet 中是很普遍的。也有一些库有助于你产生HTML。随着应用越来越复杂,Java开发人员将不再扮演HTML页面设计的角色。同时,大多数项目经理更喜欢将团队分成不同的小组。 它们喜欢HTML设计人员处理表现层的工作,而Java 工程 路基工程安全技术交底工程项目施工成本控制工程量增项单年度零星工程技术标正投影法基本原理 师则专注于业务逻辑。单独使用servlet的做法鼓励混合标记和业务逻辑,很难区分团队人员的专业工作。 为解决这个问题,Sun提出了一个将脚本和模板技术结合到一个组件中的服务器页面技术(JavaServer Pages)。为创建JSP页面, 开发者按创建HTML页面类似的方式创建页面,使用相同的HTML 语法。为将动态内容引入页面,开发人员可以将脚本元素置入页面之中。脚本元素是一些标记,封装了可以被JSP识别的逻辑。你可以在JSP页面中很容易的识别出脚本元素,他们被封装在一对<% 和 %>标记中。 为了识别JSP页面,文件需要保存为扩展名.jsp。当一个客户请求JSP页面时,容器将页面翻译成Java servlet 源代码文件,并将它编译成Java 类文件——就象你写的servlet文件一样。在运行时,容器也能检测JSP文件和相应的类的最后更新时间。如果,JSP 文件自上次编译以来被修改了,容器将重新翻译和编译JSP文件。项目经理现在可以将表现层分派给HTML 开发人员,将业务逻辑工作分派给JAVA开发人员。重要的是记住,JSP页面事实上是一个servlet。你可以在servlet做的,也可以在JSP中做。 7.JavaBean: JavaBean是一种 Java类,它遵从一定的设计模式,使它们易于和其他开发工具和组件一起使用。 定义 JavaBean 是一种JAVA 语言写成的可重用组件。要编写JavaBean,类必须是具体类和公共类,并且具有无参数的构造器(NON-ARGS CONSTRUCTOR)。JavaBean通过提供符合一致性设计模式的公共访问方法将内部字段暴露称为属性。众所周知,属性名称也符合这种模式,其他JAVA 类可以通过自省机制发现和操作这些JavaBean 属性。 我们必须做的如下: 1(编写一个类,通过实现doStart()或者doEnd()方法来实现javax.servlet.jsp.tagext.TagSupport 或者javax.servlet.jsp.tagext.BodyTagSupport接口。这些方法获得一个JspWriter对象,你可以用它来输出你需要的HTML内容。 2(创建一个标签库描述文件(TLD)来将你的新建的类,映射到一个标签名称。 3(在你的Web 应用描述符(web.xml)中定义你的 元素。通过在JSP 页面的顶部放置下面的语句:<%@tagliburi="/tags/app.tld prefix="app" %>来告诉JSP 页面你将使用你自己的标签库。 (这个语句导入将在本页中使用的标签库,并分配给它一个前缀。关于更4 多细节,请参考JSP标签库技术页面。 JavaBean 设计模式提供两种类型的方式来访问bean 的内部状态:访问器(accessor) 用来读JavaBean的状态,修改器(mutator )用来改变 JavaBean 的状态。 Mutator 通常以小写的set 前缀开始,后跟属性名。属性名的第一个字母必须大写。返回值通常是void,因为mutator 仅仅改变属性的值,而不返回它们。简单属性的mutator在其方法体中可能只有一个参数,该参数可以是各种类型。Mutator也可根据其前缀称为设置器setters。例如,对Double 类型的属性weight 的mutator方法体可能是: public void setWeight(Double weight) 相似的设计模式也用于访问器方法的创建。Accessor 通常以小写的get 为前缀,后跟属性名。属性名的第一个字母必须大写。返回值必须匹配相应的修改器方法的参数。简单属性的Accessor在其方法体中不能接受参数。同样,访问 器accessor 也经常称为获取器getter。 属性weight 的访问器方法体可能是:public Double getWeight() 如果访问器返回一个逻辑值,这种情况下有个变体模式。不使用小写的 get,逻辑属性的访问器可以使用小写的is 前缀,后跟属性名。属性名的首字母必须大写。返回值肯定是逻辑值,不管是 boolean 还是Boolean。逻辑访问器在其方法体中不能接受参数。On属性的逻辑访问器的方法体可能是:public boolean isOn() 在使用JavaBean 时,规范的方法体签名扮演了极为重要的角色。其他组件可以使用Java 的反射API 通过查找前缀为set、is或者get的方法来发现JavaBean的属性。如果一个组件在一个JavaBean 中发现一个这样的方法,它就知道这个方法可以用来访问或者改变JavaBean 的属性。Sun引入JavaBean是为了用于GUI组件,但它们已经用在Java开发的各个方面,包括Web应用。Sun的工程师在开发JSP标签的扩展类时,也被设计来可以和JavaBean一起工作。一个页面的动态数据可以使用一个JavaBean来传递,并且JSP标记可以随后使用bean的属性来定制页面的输出。 Model 2: Servlet/JSP规范的0.92 版描述了在一个应用中使用servlet和JSP的架构。在其后的规范中,Model 2 这个叫法消失了,但它已经在Java web开发人员中非常通用了。根据Model 2,servlet处理数据存取和导航流,JSP处理表现。Model 2使Java工程师和HTML设计者分别工作于它们所擅长和负责的部分。Model 2应用的一部分发生改变并不强求其他部分也跟着发生改变。HTML开发人员可以改变程序的外观和感觉,并不需要改变后端servlet的工作方式。Struts框架是基于Model 2的架构。它提供一个控制器servlet来处理导航流和一些特殊类来帮助数据访问。随框架也提供一个丰富的标签库,以使Struts易于和JSP一起使用。 小结: 在本文中,我们介绍了Struts应用框架。并介绍了一些基本知识,关于HTTP, CGI, Java servlet, JSP,以及JavaBean。我们也说明了Model 2应用架构,以及它如何用来将servlets和JSP 在结合在同一个应用之中。现在你已经有关于Strtus Web应用程序模样的初步印象,以后我们将更深入的讨论Strtuts框架的理论和具体应 用。
本文档为【基于JSP实现的餐饮管理系统毕业设计英文文献翻译】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_003124
暂无简介~
格式:doc
大小:100KB
软件:Word
页数:36
分类:工学
上传时间:2017-10-16
浏览量:137