Java Reference
In-Depth Information
Example 18−4: login.jsp (continued)
<body bgcolor='white'>
<br><br><br> <%-- Space down from the top of the page a bit --%>
<%-- A custom tag: display a decorative box --%>
<decor:box color='yellow' margin='25' borderWidth='3' title='Login'>
<div align=center> <%-- Center everything inside the box --%>
<%-- Display the login title and optional error message --%>
<font face='helvetica'><h1><%=title%></h1></font>
<font face='helvetica' color='red'><b><%=message%></b></font>
<%-- Now display an HTML form for the user to enter login information --%>
<form action='login.jsp' method='post'>
<table> <%-- Use a table to make the login form look nice --%>
<tr> <%-- First row: username --%>
<td align='right'>
<b><font face='helvetica'>Username:</font></b>
</td>
<td><input name='username'></td>
</tr><tr> <%-- Second row: password --%>
<td align='right'>
<b><font face='helvetica'>Password:</font></b>
</td>
<td><input type='password' name='password'></td>
</tr><tr> <%-- Third row: login button --%>
<td align='center' colspan=2><font face='helvetica'><b>
<input type=submit value='Login'>
</b></font></td>
</tr>
</table>
<%-- The form must also include some hidden fields so this page --%>
<%-- can pass the nextpage and title parameters back to itself --%>
<input type='hidden' name='nextpage' value='<%=nextPage%>'>
<input type='hidden' name='title' value='<%=title%>'>
</form>
</div>
</decor:box> <%-- End of the custom box tag --%>
</body>
<%-- End of the HTML output --%>
<%
} // This is one final scriptlet to close the else block started above
%>
Running login.jsp
JSP files do not need to be compiled before they are run. The JSP container auto-
matically performs the compilation the first time the JSP page is requested and
whenever the page is subsequently modified. Unlike servlet class files, which must
be placed in the WEB-INF/classes directory, JSP pages are treated just like HTML
pages or images files and can be placed anywhere in the hierarchy of user-visible
files for an application. In the sample WAR file, login.jsp is placed in the top-level
directory and accessed with a URL like the following:
http://localhost:8080/javaexamples2/login.jsp
You may notice a delay the first time you request this URL, while your JSP con-
tainer compiles the JSP file into a servlet.
In order for login.jsp to work correctly, it requires a request parameter named
nextpage , so it can redirect the user's browser somewhere after the login
Search WWH ::




Custom Search