Java Reference
In-Depth Information
Example 18−6: portal.jsp (continued)
<%-- of the 'favoriteColor' property of the 'user' bean --%>
<decor:box color='pink' margin='20'>
Your favorite color is:
<jsp:getProperty name='user' property='favoriteColor'/>
</decor:box>
</td>
<%-- This is the second cell of the table. It contains a form for --%>
<%-- selecting a favorite color. Note the technique used to output the --%>
<%-- <select> element of the form. --%>
<td>
<form method='post'> <%-- Begin the form --%>
<select name='favoriteColor'> <%-- Begin a <select> object --%>
<% // Begin a Java scriptlet
// Ask the bean for the list of color choices, and the user's favorite
String[] colors = user.getColorChoices();
String favorite = user.getFavoriteColor();
// Now start looping through the list of colors. The body of this loop
// is the HTML and JSP code below.
for(int i = 0; i < colors.length; i++) {
%>
<%-- End the scriptlet --%>
<%-- Each time through the loop, we'll output an <option> element --%>
<%-- Note the use of JSP <%=...%> expression tags to customize this --%>
<%-- option tag for each iteration of the loop --%>
<option value='<%=colors[i]%>'
<%=(colors[i].equals(favorite))?"selected":""%>
>
<%=colors[i]%>
<%-- Label of <option> element --%>
</option>
<%}%> <%-- End the for loop --%>
</select> <%-- End the <select> object --%>
<input type=submit value='Select'> <%-- Submit button for the form --%>
</form>
<%-- End the form--%>
</td></tr></table>
<%-- End of 2nd cell and the table --%>
</decor:box>
<%-- End of the box --%>
<%-- Begin a new box. This one also contains a 2-cell table --%>
<br>
<decor:box title='Logout when Done' color='lightblue'>
<table><tr><td valign=top>
<%-- The first table cell is a simple form that allows the user to logout --%>
<%-- See Logout.java
for details --%>
<form action='servlet/logout' method='post'>
<input type=hidden name='page' value='../portal.jsp'>
<font face='helvetica'><b><input type='submit' value='Logout'></b></font>
</form>
<%-- The second item in the box is another box that displays counts --%>
<%-- We use jsp:include twice more to invoke the Counter servlet. --%>
<%-- Note that for the 2nd inclusion, we rely on the fact that the web.xml --%>
<%-- file maps any URL ending in ".count" to the Counter servlet --%>
</td><td valign=top>
<decor:box color='#a0a0c0' margin='5' borderWidth='1'>
You have visited
<jsp:include page='servlet/counter' flush='true'>
<jsp:param name='counter'
value='<%="portaluser_"+session.getAttribute("username")%>'/>
Search WWH ::




Custom Search