JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   




(Continued from antecedent part...)




Using Java Altar as Java Beans



Now we understand that a Java Bean is just a accustomed Java item with some distinctively named


methods, and stored in pageContext s aspect collection. We can use the useBean


to make a JavaBean and use it any way we wanted.



The next catechism is: can we make any item and put it into pageContext s attribute


collection, and use setProperty and getProperty elements? The acknowledgment is yes. Here


is my sample JSP page to appearance you this:




<?xml version="1.0"?>


<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">


<!-- ObjectAsBean.jsp


Absorb (c) 2003 by Dr. Yang








.DemoBean b = new .DemoBean();


pageContext.setAttribute("b", b, PageContext.PAGE_SCOPE);








Line 21: columnist =


<jsp:getProperty name="b" property="author"/><br/>


Line 22: absolute =


<jsp:getProperty name="b" property="total"/><br/>




Line 23: admeasurement =


<jsp:getProperty name="b" property="size"/><br/>


Line 24: admeasurement =








java.util.Date d = new java.util.Date();


pageContext.setAttribute("d", d, PageContext.PAGE_SCOPE);




<jsp:setProperty name="d" property="time" value="1000000000000"/>


Line 25: time =


<jsp:getProperty name="d" property="time"/><br/>








Open this JSP page with IE, you will get:




Line 21: columnist = Unknown


Line 22: absolute = double: 9.99


Line 23: admeasurement = int: 15


Line 24: admeasurement = int: 15


Line 25: time = 1000000000000




Note that:



  • Line 25 tells us that we can even make a Date item and create it accessible a


    JavaBean. Its setTime and getTime methods are acclimated accommodate the time property.






Refreshing the Loaded Bean Classes



Once a bean chic has been acclimated already by a JSP page, it will break loaded in anamnesis


to abstain loading it afresh if addition JSP page uses it. This is acceptable to advance


response time, but it is a problem if you afflicted your bean and wants to advance


the newer adaptation into the server.



One way to force the server to use the new versions of bean classes is to shut down


the server and re-start the server.



But a bigger way to force the server to use the new versions is to use the Bobcat


Manger tool. Actuality is how to do this:



1. Set up a administrator user name and countersign by abacus the afterward band to


localjakarta-tomcat-4.1.18conf omcat-users.xml:




<user username="" password="yang" roles="manager"/>




2. Shut down and re-start Bobcat server.



3. Appeal UseBean.jsp with IE.



4. Adapt CacheBean.java, abridge it, and archetype the chic book the .web-infclasses.



5. Run the "reload" command with IE at http://localhost:8080/manager/reload?path=/.


You charge access user name and countersign created in move 1.



6. Appeal UseBean.jsp again. You should see the changes create to CacheBean.java in move 4.





Tags: create, server, classes, property, author, notes, manager, tutorial, tutorials, object

 scriptlet, property, pagecontext, server, getproperty, javabean, cdata, tomcat, manager, password, object, total, classes, author, create, version, , < jsp, jsp scriptlet, scriptlet <, jsp page, getproperty name, jsp getproperty, < cdata, > <, size <, jsp getproperty name, jsp scriptlet line, java util date, pagecontext page scope, notes using javabean, tutorials tutorial notes, tutorial notes using, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Article In : Computers & Technology  -  jsp