29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.4.2 Servlets<br />

► request<br />

► response<br />

► pageContext<br />

► session<br />

► application<br />

► out<br />

► config<br />

► page<br />

► exception<br />

Java servlets are Java alternatives to Common Gateway Interface (CGI)<br />

programs. As with CGI programs, Java servlets can respond to user events from<br />

an HTML request, and then dynamically construct an HTML response that is sent<br />

back to the client. Java servlets have the following advantages over traditional<br />

CGI programs:<br />

► Java-based<br />

Because Java servlets are written in Java, they inherit all the benefits of the<br />

Java technologies.<br />

► Persistence and performance<br />

A servlet is loaded once by a Web server and invoked for each client request.<br />

Java servlets do not incur the overhead of instantiating a new servlet with<br />

each request. CGI processes typically must be loaded with each invocation.<br />

Java servlets can work better than CGI programs, especially for business logic<br />

and control flow.<br />

However, for a servlet to return an HTML page to a browser, it must output HTML<br />

from within the Java code. A Java programmer has to write many out.println<br />

statements to return the HTML. This mixes the roles of the content developer and<br />

the Java programmer, even limiting the usefulness of content-authoring tools.<br />

Java<strong>Server</strong> Pages were developed to address the problem of writing HTML<br />

statements in Java source code.<br />

2.4.3 Java<strong>Server</strong> Pages<br />

Java<strong>Server</strong> Pages are an HTML extension for doing server-side scripting in Web<br />

pages. Java<strong>Server</strong> Pages are similar to HTML files, but provide the ability to<br />

display dynamic content within Web pages. Here are some of the advantages of<br />

using Java<strong>Server</strong> Pages technology over other methods of dynamic content<br />

creation:<br />

Chapter 2. <strong>Application</strong> design 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!