Generating HTML from a Query Result
Just before the
page in Example 12-1
redirects to the confirmation page, there’s one more
<sql:query>
action that retrieves the
employee information that was just stored in the database:
<sql:query var="newEmpDbInfo" scope="session"> SELECT * FROM Employee WHERE UserName = ? <sql:param value="${param.userName}" /> </sql:query>
The intention here is to present the information actually stored in the database to the user on the final page in this application (shown in Figure 12-5) as a confirmation that the operation was successful.
Since we redirect to the confirmation page, ending the processing of the current request, the result is placed in the session scope. The redirect response tells the browser to automatically make a new request for the confirmation page. Because the new request is part of the same session, it finds the result saved by the previous page. Example 12-2 shows the code for the confirmation.jsp page.
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<title>Employee Info Stored</title>
</head>
<body bgcolor="white">
This is the information stored in the employee database:
<table>
<c:forEach ...
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.