[Change] JavaBean introduce

sponsored links
From the Java language's point of view, JavaBean is a purely a Java class, which abide by some rules and naming, for example, it is an open category, with a public setter and getter methods, support for event handling, etc., JavaBean is a reusable components can be used to design the user interface components, or used in JSP pages and data logic processing to carry.

For dynamic pages, if it is also responsible for the generation of Web content, is also responsible for data processing and preservation, the final result often is a part of page rendering with the program logic processing, and handling of data objects mixed in together, on the need to cooperate with each other website designers and programmers alike a kind of troubled, JavaBean One of the roles is to want to program the logic to deal with rendering part of the separation
For the JSP designers, it should make full use of technologies such as JavaBean (that is, there are other technologies) to separate the presentation of programs and web pages.

JavaBean's writing as a general Java program, let's write a simple Java class, its role is to find the greatest common factor of two numbers:
package beantools.math;
public class FindGCD 
{    
   private int m, n;    
   public void setM(int m) 
   {        
      this.m = m;    
   }    
   public void setN(int n) 
   {        
      this.n = n;    
   }    
   public int getGCD() 
   {        
      int r = 0;        
      while(n != 0) 
      {            
         r = m % n;            
         m = n;            
         n = r;        
      }        
      return m;    
   }
}


Note that in JSP 2.0, after, JavaBean class must have a package to be managed; above methods in this category are owned by the public,
And using setXXX () and getXXX () approach to naming, will compile this class is complete, you will type *. class placed on the Web application WEB-INF/classes / folder, note that because we set the package to beantools . math, so in the end of your *. class
Should be the path should be WEB-INF/classes/beantools/math/FindGCD.class, then we will be in this category in the JSP pages to use as a JavaBean, we write the JSP page the following programs:
<jsp:useBean />
<jsp:setProperty name="gcd" property="*" />
<%= request.getParameter("m") %>  And  <%= request.getParameter("n") %>
 Greatest common divisor:  <jsp:getProperty name="gcd" property="GCD" />


<jsp:useBean> tag is used to call JavaBean methods, id is used to specify a reference name of the JavaBean instance, it actually will be converted to
Servlet in an object reference to the name, class to specify your JavaBean which will be an instance of a category, in the implementation of the JSP page,
It will check whether an instance of JavaBean already exists, if does not exist, then an instance of a JavaBean.

<jsp:setProperty> tags used to set the JavaBean property values, name used to specify which you want to use a reference to the name a reference to the
JavaBean instance; in property to set when we use the introspection mechanism to set the property "*" that will automatically search for
request that meets the JavaBean in the name of the parameter value setter that if the request parameter name if they meet the setXXX () in the XXX name,
Will request the corresponding value is set to setXXX ().

<jsp:getProperty> is used to access JavaBean property values carried by, name used to specify which you want to use a reference to the name a reference to the JavaBean instance is specified in the property to which an attribute value, that is, if designated as a XXX, using getXXX () method to obtain the value.
We are directly in the address bar to send the following message can obtain the greatest common factor:
http://localhost:8080/myjsp/javabeandemo.jsp?m=100&n=14


The back reads as follows:
100  And 14 of the greatest common divisor: 2  


As shown above, using JavaBean, we can move some of the programmable logic JavaBean in JSP pages without having to write code directly in logic, as long as the JSP page to use <jsp:useBean>, <jsp:setProperty> and <jsp:getProperty> such as labels, tags used in HTML pages more intuitive, not with a lot of programmable logic portion can have a "majority of the" view and the logical separation of purpose (alone JavaBean to achieve full separation is still difficult).
It should be noted is that whenever you change the contents of the JavaBean programming and re-compiled, Container may not necessarily be aware of the contents of the JavaBean has changed, there will be no re-loaded after the change a new category, which is one of the shortcomings of using the JavaBean The solution is to re-start
Container, so that changes in Container reloading after JavaBean.

ref:
http://www.javaworld.com.tw/jute/post/view?bid=6&id=52686&sty=1&tpg=1&age=-1
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of [Change] JavaBean introduce

  • RoR explained

    ROR is Ruby on Rails. Ruby is a well-known has been very good dynamic language It's dynamic language. Simple and easy. Dynamic languages are interpreted, but the performance may make a discount, but not absolute, because the application is complex, th

  • hibernate call stored procedure

    hibernate call stored procedure

  • Some interview questions java

    The first is the company give you a chance to meet, it is necessary to know to meet from time to equal the interview, and have a lot of companies to see you at the first time will give you a ready point of doing something trivial, these questions, althoug

  • JAVA Class naming convention

    1. Entity Layer: Inheritance: All categories inherited from BasicEntity, one of BasicEntity implementation java.io.Serializable interface; Naming rules: Class Name = Object + type suffix, one of type suffix for Bean, such as: SalesOrderBean 2. Form l ...

  • spring + hibernate + oracle9i to read and write CLOB

    Database-driven update classes12-9i.jar Hibernate modify the configuration of the following code <bean/> <bean Lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativejdbcExtractor"/>

  • 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 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

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