Java - JavaServer Pages (JSP)

Java Conceptuel Diagram

About

JavaServer Pages technology lets you put:

directly into a text-based document.

A JSP page is a text-based document that contains two types of text:

  • static template data, which can be expressed in any text-based format such as HTML, WML, and XML,
  • and JSP elements, which determine how the page constructs dynamic content.

The jsp extension notifies the Web server that the page should be processed by a JSP container. The JSP container interprets the JSP tags and scriptlets, generates the content required, and sends the results back to the client as an HTML or XML page.

JSP technology is considered to be a deprecated presentation technology for JavaServer Faces.

Jsp files are converted into Java files at runtime, just before they are compiled by javac.

Element

Jsp Element:

Tags

JSP tags are used for tasks such as

  • initializing Java classes, JavaBean
  • forwarding the user to either the same or another page in the application.

Example:

  • jsp:useBean. It identifies and initializes the class that holds the methods that run in the page.
  • jsp:forward. This tag is used to forward the user to a specified page.

Scriptlets

Scriptlets are used to run the Java methods that operate on the database and to perform other processing in JSP pages.

You use scriplets for a variety of tasks.

For example:

  • to call a method that returns a ResultSet object and use it to display that data.
  • to iterate through a same ResultSet object and display each item in a row of a table.

Example

<jsp:useBean id="empsbean" class="hr.DataHandler" scope="session"/>
         
         
<%
ResultSet rset;
String query = request.getParameter("query");
if (query != null && query != null) {
    rset = empsbean.getEmployeesByName(query);
} else {
    rset = empsbean.getAllEmployees();
}
%>
<table cellspacing="2" cellpadding="3" border="1" width="100%">
    <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Email</th>
        <th>Job</th>
        <th>Phone</th>
        <th>Salary</th>
    </tr>
     
<%
while (rset.next ())
{
out.println("<tr>");
out.println("<td>" + 
rset.getString("first_name") + "</td><td> " + 
rset.getString("last_name") + "</td><td> " + 
rset.getString("email") + "</td><td> " + 
rset.getString("job_id") + "</td><td>" + 
rset.getString("phone_number") + "</td><td>" + 
rset.getDouble("salary") + "</td><td> <a href=\"edit.jsp?empid=" 
+ rset.getInt(1) + "\">Edit</a></td>");
out.println("</tr>");
}

empsbean.closeAll();
%>
</table>

Documentation / Reference





Discover More
Card Puncher Data Processing
Eclipse - Oracle Enterprise Pack for Eclipse (OEPE)

Oracle Enterprise Pack for Eclipse (OEPE) provides development support for: ADF Faces and ADF Controller. Oracle Enterprise Pack for Eclipse (OEPE) 12.1.1.0 for Eclipse Indigo provides tools that...
Card Puncher Data Processing
JPA - Entity Manager

To manage entities in your persistence application, you need to obtain an javax/persistence/EntityManagerentity manager from an javax/persistence/EntityManagerFactoryEntityManagerFactory. An javax/persistence/EntityManagerEntityManager...
Java Conceptuel Diagram
Java - ( JDK | J2EE | J2SE )

SDK in Java core APIs for writing J2EE components, core development tools, and the Java virtual machine JDBC API 2.0 The Java 2 Platform, Standard Edition (J2SE) SDK is required to run...
J2ee Server
Java - Application Server

application server in Java A J2EE Server is application server on the J2EE platform. It contains the web-tier and the business tier where the components are placed in logical container. Tier Components...
J2ee Server
Java - Container

A container is a logical part of a J2EE Server which contains java components Before any component can be executed, it must be assembled. The assembly process involves per logical container: the...
Java Conceptuel Diagram
Java - Expression Language (EL)

The Expression Language (also referred to as the EL) provides an important mechanism for enabling the presentation layer (web pages) to communicate with the application logic (managed beans). The EL...
Java Conceptuel Diagram
Java - J2EE Web components

J2EE Web components can be either: Java Servlet JavaServer Pages (JSP) or web pages implemented with JavaServer Faces technology, web service endpoints Servlets are Java programming language...
J2ee Multitier Architecture
Java EE - (J2EE|JEE) Platform

The J2EE platform offers: a multitiered distributed application model, the ability to reuse components, integrated Extensible Markup Language (XML)-based data interchange, a unified security...



Share this page:
Follow us:
Task Runner