Chapter 14: JavaServer Pages

Overview

JavaServer Pages (JSPs) are server-side components that allow developers to create applications that are accessible from the Internet. They combine Hypertext Markup Language (HTML) and Java to create a programming paradigm that does not require an extensive knowledge of Java. JSPs are specifically designed to handle the request and deliver a response in the form of HTML. The generated HTML page can also contain JavaScript to increase its functionality. Every action involves a request and the subsequent response in the form of an HTML document. It is possible to generate other types of documents such as Extensible Markup Language (XML) using JSPs. Behind the request/response cycle is the HTTP protocol. HTTP provides the mechanism that allows the client and server to communicate. The client is typically an Internet browser such as Microsoft s Internet Explorer or Netscape Navigator. If you have a good understanding of HTTP, it will make creating JSPs much easier.

Note  

For a detailed description of the HTTP protocol, go to http://www.w3.org/Protocols/. Hundreds of other web resources are available as well.

Before a JSP can be served , it must be translated into a servlet, compiled, and deployed. Using the syntax elements available, JSPs are coded to deliver dynamic content in the form of an HTML page. The JSP compiler then does the work of translating it into a servlet. A JSP is what is requested , but a servlet is what delivers the response.

JSPs are accessed through a URL, just as HTML pages are. Typically, these URLs end in a .jsp extension. For example, the URL http://www.example.com/index.jsp requests that the index.jsp page handle the request. If the page has not yet been compiled or has been updated, the server will translate the JSP into the required Java code and then compile the servlet. The servlet then processes the request. Typically, the request involves interaction with an HTML form.

JSPs were designed with simplicity in mind so that JSP developers would not have to know Java. While in its purest implementation this is true, in practice this is normally not the case. A fair level of Java knowledge will go a long way in making you a better JSP developer.

JSPs give developers access to tag libraries that they can use that create dynamic content. Tag libraries are often created by developers with a good understanding of Java. Once the tag library is created, it can be used in any number of JSPs. Using the custom tag libraries allows JSP developers to code complex functionality into their pages without having to know how it is implemented.

You can place Java code directly in your JSP in the form of scriptlets, but this is not recommended as doing so increases the complexity and decreases the maintainability of your JSPs. More often than not, when you see Java code inside JSPs, you will find there is a lot of duplicated functionality across the application s pages.

Coding a JSP is similar to creating an HTML document. Oracle JDeveloper 10 g provides a graphical user interface to develop JSPs. See Chapter 13, Oracle JDeveloper, for more information on using Oracle JDeveloper 10 g to develop JSP applications. All of the examples created in this chapter were created with Oracle JDeveloper 10 g 9.0.5.2.

Note  

Oracle JDeveloper 10g can be downloaded from the Oracle Technology Network web site at: http://www.oracle.com/technology/software/products/jdev/index.html.



Oracle Application Server 10g Web Development
Oracle Application Server 10g Web Development (Oracle Press)
ISBN: 0072255110
EAN: 2147483647
Year: 2004
Pages: 192

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net