In the foregoing explanation, you have already understood how to create a Javabean, now let's take a look at it, in this article we will use the previous example, if you have not seen, I suggest you look at it. Ok, start!!
Before we continue to describe how to write a JSP call JavaBean, let's discuss the three Tags of JSP to use JavaBean.
i.
ID = "Object-name" Scope = "Page | Session | Application" TYPE = "type-of-object" Class = "full-qualified-classname" Beanname = "full-qualified-beanname" /> Let's take a look at these properties: ID - The name of the object, such as: string name = null; in this code, Name is ID; Scope - an optional property that when your JavaBean object will be destroyed, the default is Page, he means that each page will create a new JavaBean; Type - The type of object can be the same class or parent class or the interface to be executed, his parameters are optional. Such as: string name = "faisal khan"; String is what we talk about . Class - a completely qualified class such as: DATE D = new java.util.date (); java.util.date is what we said. Beanname - is also a class completely qualified; II. Name = "id-of-the-javabean" Property = "Name-of-Property" Param = "name-of-required-parameter-to-use" Value = "new-value-of-this-protety" /> The attribute is: Name - 'ID' of Property - the name of the Property you want to set PARAM - the name of Param you want to request in your property Value --- New value you want to set in this property III. Name = "name-of-the-object" Property = "Name-of-Property" /> Properties: Name - Property - the name of the Property you want to retrieve Ok, we now complete the JSP tags of learning operation Javabean, let us take some time to learn what is scope attribute: Every JavaBean class object or other class object has a scope, what he means to keep how long this object is kept in memory, here there are four scopes: Page - He means a new object will be created or destroyed at each page level. When you don't make a clear given other values, he is Request - He means that the creation of new objects will be bound to the Request object, which means he time the time range when you enter a URL Request page. When you turn off the web. You are in any JSP that is executed Use beans in the file until the page execution is sent back to the client or go to another file until SESSION - from the creation bean, you can use Bean in any JSP file using the same session. This bean exists all over During the Session Survival period, any JSP files that share this session can use the same bean. Note that in the <% @ Page%> command in the JSP file you create, you must specify session = true Application - starting from creating a bean, you can use bean in any JSP file using the same Application. This bean exists within the entire Application Licheng, any JSP file that is shared this Application can use the same bean; this is very Useful for page access counts. Create a new SimpleBean.jsp and save him in the / web-app folder, / web-app is a complete Web Application path, such as c: / yoursite, save SimpleBean.jsp Save as C: / YourSite The code is as follows: hEAD>
<% - CREANG JAVABEANS -%>
jsp: usebean>
<% - Displaying JavaBean Property's Value -%>
name retrieved from JavaBean Has The Value of:
Age Retrieved from Javabean Has The Value of:
p>
body>
html> Note:
---- Set the value of different Name and AGE in our SimpleBean Class.
jsp: usebean> ----- End
Next, let's see the value of Properties:
see how easy ah.!