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
-
What Is Visual Basic and Why do I need it? Visual Basic is Easy to learn Programming language. With Visual Basic you can develop Windows bas...
-
Learning about Properties Every component (form is component for example) has properties, that determine its look and its functioning. Prope...
-
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 ...
-
As you may already know, the C++ Standard Library implements a powerful string class, which is very useful to handle and manipulate strings ...
-
A JSP expression is used to insert Java values directly into the output. It has the following form: <%= Java Expression %> The Java ex...
-
XML Web Services A Web Service (XML Web Service) is a unit of code that can be activated using HTTP requests. Stated another way, a Web Serv...
-
.NET is a "Software Platform". It is a language-neutral environment for developing rich .NET experiences and building applications...
-
request This is the HttpServletRequest associated with the request, and lets you look at the request parameters (via getParameter), the requ...
-
MS SQL Server or simply SQL Server is RDBMS developed by Microsoft Corp. SQL Server uses a dialect of SQL called Transact-SQL (T-SQL). The S...
-
Differences Between Java and C/C++ It is no secret that the Java language is highly derived from the C and C++ languages. Because C++ is cur...
No comments:
Post a Comment