1 / 10

Chapter 6

Chapter 6. Using JavaBeans Components in JSP Pages. What Is a Bean?. Implement a Java Bean. use a package name A bean class must have a no-argument constructor The bean properties are accessed through getter and setter methods

derex
Télécharger la présentation

Chapter 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Using JavaBeans Components in JSP Pages

  2. What Is a Bean?

  3. Implement a Java Bean • use a package name • A bean class must have a no-argument constructor • The bean properties are accessed through getter and setter methods • the bean class should implement the java.io.Serializable or the java.io.Externalizable interface • The property name is case-sensitive and always starts with a lowercase letter

  4. Declaring a Bean in a JSP Page

  5. Reading Bean Properties • Using the <jsp:getProperty> Action • <jsp:getProperty name="cartoon" property="fileName" /> • Using the JSP Expression Language • <img src="images/${cartoon.fileName}"> • If you need to generate an image dynamically, you should use a servlet • <img src="imageGenServlet?width=100&height=100">

  6. Setting Bean Properties • Using the <jsp:setProperty> Action • <jsp:setProperty name="msg" property="category" value="thoughts" /> • Using the JSTL <c:set> Action • <c:set target="${msg}" property="category" value="thoughts" />

  7. To set a JSP action attribute to the value produced by another action

  8. Automatic Type Conversions • When you use the <jsp:setProperty> or the JSTL <c:set> action, the container takes care automatically of the conversion from text values to the Java types

  9. Conversion of text value to property type

  10. Setup JavaBean • Setup Environment Variables • path %java_home%\bin;%path% • set ClassPath %java_home%\lib • Compile JavaBean • Javac CartoonBean.java • Javac –classpath servlet-api.jar MyServlet.java • Create directories in classes • com\ora\jsp\beans\motd • Copy MyBean.class to com\ora\jsp\beans\motd • Reload Web Application

More Related