Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Create the Output JSP That Displays a Message

Create another JSP, showmessage.jsp, which displays a message assuming that an instance of Message called "message" exists in the request scope. There are three ways of displaying the properties of a scoped variable:

  • Use an expression such as <%= message.getId()%>
  • Use the getProperty tag, such as <jsp:getProperty name="message" property="name"/>
  • Use strut's htmlProperty custom tag. This tag ensures that the HTML-sensitive characters such as < and > are aptly filtered for display.

Listing 2 shows how you can display the properties of Message using a combination of the three methods.

Listing 2 showmessage.jsp

<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>
<jsp:useBean id="message" class="Message" scope="request"/>
    <title><struts:htmlProperty name="message" property="subject"/></title>
<body bgcolor="#ffffbb">
<a href="create.do?parentId=<%= message.getId()%>">
<struts:message key="showmessage.reply"/></a>
<table border="1" cellpadding="1" width="100%" bgcolor="white">
    <td><b><struts:message key="showmessage.name"/></b></td>
    <td><a href="mailto:<jsp:getProperty name="message" property="email"/>">
    <jsp:getProperty name="message" property="name"/></a></td>
    <td><b><struts:message key="showmessage.when"/></b></td>
    <td><jsp:getProperty name="message" property="timestamp"/></td>
    <td><b><struts:message key="showmessage.subject"/></b></td>
    <td><h2><struts:htmlProperty name="message" property="subject"/></h2></td>
<struts:htmlProperty name="message" property="body"/>
  • + Share This
  • 🔖 Save To Your Account