Java Servlets

StringBean Example

package mywebapp;
/** A simple bean that has a single String property
 * called message.
 */
public class StringBean {

  private String message = "No message specified";

  public String getMessage() {
    return(message);
  }

  public void setMessage(String message) {
    this.message = message;
  }
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  <HEAD>
    <TITLE>Using JavaBeans with JSP</TITLE>
    <LINK REL=STYLESHEET
      HREF="JSP-Styles.css"
      TYPE="text/css">
  </HEAD>
  <BODY>
    <TABLE BORDER=5 ALIGN="CENTER">
        <TR><TH CLASS="TITLE">
            Using JavaBeans with JSP</TABLE>
    <jsp:useBean id="stringBean" class="coreservlets.StringBean"/>
      <OL>
       <LI>Initial value (from jsp:getProperty):
        <I><jsp:getProperty name="stringBean"   property="message" /></I></LI>

        <LI>Initial value (from JSP expression):
          <I><%= stringBean.getMessage() %></I></LI>

        <LI><jsp:setProperty name="stringBean" property="message" value="Best string bean: Fortex" />
          Value after setting property with jsp:setProperty:
          <I><jsp:getProperty name="stringBean" property="message" /></I>

        <LI><% stringBean.setMessage("My favorite: Kentucky Wonder"); %>
      Value after setting property with scriptlet:
            <I><%= stringBean.getMessage() %></I>
      </OL>
  </BODY></HTML>

José M. Vidal .

77 of 89