JavaBean in JSP documents form the application of (14.1)


Advertisements


Build bean: jsp: useBean

<jsp:useBean />
Phrase generally means "an instance of the class specified by the class, and instantiated objects bound to _jspService variables, the variable name specified by id." Note, however, be sure to use the fully qualified class name - including the application class name. Whether you use <% @ page import ...%> enter the package, must meet this requirement.

jsp: useBean class attribute must use the fully qualified class name.

For example, the general JSP actions can be
<jsp:useBean />
That is below the equivalent of this scriptlet
<% Coreservlets.Book book1 = new coreservlets.Book ();%>

installation of the bean class

All are placed in the bean package. Installation is usually used to store the java code in the directory: a single class on WEB-INF/classes/subdirectory, JAR file in the WEB-INF/lib

jsp: useBean options
scope, beanName and type jsp: useBean provides several options to provide more features, described as follows: scope: bean's scope (application, page, session, request) beanName: bean name, both can point to the corresponding bean The class name can point to an object containing the serialized bean file name, beanName attribute values ​​are passed to the javabeansBean.instantiate method type: bean type of statement used to define a bean to a super class or the actual bean implementation interface, if the type is not compatible with the situation will throw a ClassCastException exception if the Bean is already there, eliminating the need for the class attribute directly with the type attribute.

As follows <jsp:useBean type="java.lang.Runnable" /> converted into a servlet, the code is as follows:
java.lang.Runnable thread1 = new mypackage.MyClass ();
jsp: useBean only in the absence of the same id and scope of the time will instantiate a new bean.

Access bean properties: jsp: getProperty

In the jsp: useBean in, bean name given by the id attribute. In the jsp: getProperty and jsp: setProperty, by the name attribute is given.

Like if you like the above code creates a book1 object, then we can use the following code to get book1 of the title attribute value.
<jsp:getProperty name="book1" property="title" />
<% = Book1.getTitle ()%>
Best to use the first method, and so the same method used above to create a.

[Color = blue simple bean properties are set: jsp: setProperty [/ color]
<Jsp: setProperty name = "book1"
property = "title"
value = "Core Servlets and JavaServer Pages" />
<% Book1.setTitle ("Core Servlets and JavaServer Pages");%>
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of JavaBean in JSP documents form the application of (14.1)

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • Great collection of java interview topics

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries