Table of Contents

Java - JavaServer Pages (JSP)

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:

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

Example:

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:

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