JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HTML. You simply write the regular HTML in the normal manner, using whatever Web-page-building tools you normally use. You then enclose the code for the dynamic parts in special tags, most of which start with "<%" and end with "%>". For example, here is a section of a JSP page that results in something like "Thanks for ordering Core Web Programming" for a URL of http://host/OrderConfirmation.jsp?title=Core+Web+Programming:
Thanks for ordering
<%= request.getParameter("title") %>
You normally give your file a .jsp extension, and typically install it in any place you could place a normal Web page. Although what you write often looks more like a regular HTML file than a servlet, behind the scenes, the JSP page just gets converted to a normal servlet, with the static HTML simply being printed to the output stream associated with the servlet's service method. This is normally done the first time the page is requested, and developers can simply request the page themselves when first installing it if they want to be sure that the first real user doesn't get a momentary delay when the JSP page is translated to a servlet and the servlet is compiled and loaded. Note also that many Web servers let you define aliases that so that a URL that appears to reference an HTML file really points to a servlet or JSP page.
Aside from the regular HTML, there are three main types of JSP constructs that you embed in a page: scripting elements, directives, and actions. Scripting elements let you specify Java code that will become part of the resultant servlet, directives let you control the overall structure of the servlet, and actions let you specify existing components that should be used, and otherwise control the behavior of the JSP engine. To simplify the scripting elements, you have access to a number of predefined variables such as request in the snippet above.
Note that this tutorial covers version 1.0 of the JSP specification. JSP has changed dramatically since version 0.92, and although these changes were almost entirely for the better, you should note that version 1.0 JSP pages are almost totally incompatible with the earlier JSP engines. Note that this JSP tutorial is part of a larger tutorial on servlets and JSP at http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/.
Popular Posts
-
5.3 Draw.aspx Web Applications I am just about to finish this tutorial. I have given you a couple of code samples to chew on, but t...
-
Advantages of MS Access MS Access is a light weight database managements system. Also, it provides it's own designer so that you can gen...
-
4.3 Using the FCL “Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.” The IO strea...
-
Console Applications Console Applications are command-line oriented applications that allow us to read characters from the console, write ch...
-
Input/Output with files C++ provides the following classes to perform output and input of characters to/from files: * ofstream: Stream c...
-
Conditional Statements If....Else statement If conditional expression is one of the most useful control structures which allows us to execut...
-
Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object...
-
Getting Started (Continue) Look at the form with the title bar Form1. This is how your program will look like. Everything you will place on ...
-
Adding Controls to the Form There are many controls you can use with your program: Buttons, Text Boxes, Pictures, Scroll Bars and more. You ...
-
Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to...
No comments:
Post a Comment