Vous êtes sur la page 1sur 3

Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML.

Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Here's an example: vs. Active Server Pages (ASP). ASP is a similar technology from Microsoft. The advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual Basic or other MS-specific language, so it is more powerful and easier to use. Second, it is portable to other operating systems and nonMicrosoft Web servers. vs. Pure Servlets. JSP doesn't give you anything that you couldn't in principle do with a servlet. But it is more convenient to write (and to modify!) regular HTML than to have a zillion println statements that generate the HTML. Plus, by separating the look from the content you can put different people on different tasks: your Web page design experts can build the HTML, leaving places for your servlet programmers to insert the dynamic content. vs. Server-Side Includes (SSI). SSI is a widely-supported technology for including externally-defined pieces into a static Web page. JSP is better because it lets you use servlets instead of a separate program to generate that dynamic part. Besides, SSI is really only intended for simple inclusions, not for "real" programs that use form data, make database connections, and the like. vs. JavaScript. JavaScript can generate HTML dynamically on the client. This is a useful capability, but only handles situations where the dynamic information is based on the client's environment. With the exception of cookies, HTTP and form submission data is not available to JavaScript. And, since it runs on the client, JavaScript can't access server-side resources like databases, catalogs, pricing information, and the like. vs. Static HTML. Regular HTML, of course, cannot contain dynamic information. JSP is so easy and convenient that it is quite feasible to augment HTML pages that only benefit marginally by the insertion of small amounts of dynamic data. Previously, the cost of using dynamic data would preclude its use in all but the most valuable instances. In short, the advantages of using JSP over competing technologies are as follows:

JSP enables a clean separation of business logic from presentation. JSP, by using Java as the scripting language, is not limited to a specific vendor platform. JSP, as an integral part of the J2EE architecture, has full access to serverside resources

The JSP Model 2 architecture. Architecturally, JSP may be viewed as a high-level abstraction of Java servlets. JSPs are translated into servlets at runtime; each JSP's servlet is cached and re-used until the original JSP is modified.[2] JSP can be used independently or as the view component of a server-side model viewcontroller design, normally with JavaBeans as the model and Java servlets (or a framework such as Apache Struts) as the controller. This is a type of Model 2 architecture.[3] JSP allows Java code and certain pre-defined actions to be interleaved with static web markup content, with the resulting page being compiled and executed on the server to deliver a document. The compiled pages, as well as any dependent Java libraries, use Java bytecode rather than a native software format. Like any other Java program, they must be executed within a Java virtual machine (JVM) that integrates with the server's host operating system to provide an abstract platformneutral environment. JSPs are usually used to deliver HTML and XML documents, but through the use of OutputStream, they can deliver other types of data as well.[4] The Web container creates JSP implicit objects like pageContext, servletContext, session, request & response.

Syntax[edit source | editbeta]


JSP pages use several delimiters for scripting functions. The most basic is < % ... %>, which encloses a JSP scriptlet. A scriptlet is a fragment of Java code that is run when the user requests the page. Other common delimiters include < %= ... %> for expressions, where the scriptlet and delimiters are replaced with the result of evaluating the expression, and directives, denoted with <%@ ... %>.[5]

Java code is not required to be complete or self-contained within its scriptlet element block, but can straddle markup content providing the page as a whole is syntactically correct. For example, any Java if/for/while blocks opened in one scriptlet element must be correctly closed in a later element for the page to successfully compile. Markup which falls inside a split block of code is subject to that code, so markup inside an if block will only appear in the output when the if condition evaluates to true; likewise, markup inside a loop construct may appear multiple times in the output depending upon how many times the loop body runs.

We support many different types of java technologies. You are welcome to go ahead and review our Java VPS Hosting page. Because JSP pages are translated, and then compiled into Java servlets, errors that creep in your pages are rarely seen as errors arising from the coding of JSP pages. Instead, such errors are seen as either Java servlet errors or HTML errors. You could look at this as an example of a perceived strength of JSP that of not needing to compile them as opposed to a weakness. For example, a JSP developer coding a scriptlet where a JSP declaration is called for would have to interpret a Java compile error. The JSP developer would need access to the generated source to properly diagnose the error. Of course, generated code is rarely a thing of beauty, and often, not easily understood. The JSP developer needs to know Java. Again, one developer s asset is another s liability. Whereas Java is certainly more full-featured and flexible than other page scripting languages, no one can argue that the learning curve for Java is far steeper than other scripting languages. If you already know Java (you do, right?), this is not an issue. However, if a corporation is short on Java mavens but wants to use a dynamic Web technology, JSP may not be the route to go. (Another way to look at the need to know Java is that if you had to train a rookie in using either JSP or, say, ASP, and you had two days to produce half a dozen pages, which technology would you opt for?)

JSP Versus Java Servlets


Before the advent of JSP, the most-used Java technology that could generate dynamic Web page content was Java servlets. Because JSPs eventually are compiled into Java servlets, you can do as much with JSPs as you can do with Java servlets.

Vous aimerez peut-être aussi