Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with the <jsp:useBean> tag

843840Sep 17 2008 — edited Sep 19 2008
Dear Fellow Java/JSP developers:

I am trying to use the <jsp:useBean> tag in a jsp that displays the values from a javaBean that gets populated by another class.
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "java.util.Iterator"%>
<%@ page import = "salattimes.CalendarParse" %>
<%@ page import = "salattimes.Salat" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <jsp:useBean id="test" scope="session" class="calendar.Time" />
        <% CalendarParse sTime = new CalendarParse(); 
            Time mytime = sTime.runExample();%>
        <%=mytime.getA() %>
        <%=mytime.getB() %>
        <%=mytime.getC() %>
        <%=mytime.getD() %>
        <%=mytime.getE() %>

    </body>
</html>
However, up to now, I am only able to display the values on my JSP page using the scriptlet
<% CalendarParse sTime = new CalendarParse(); 
            Time mytime = sTime.runExample();%>
to declare and create the object (the method call sTime.runExample(); populates the fields in the Java Bean), and the expressions:
<%=mytime.getA() %>
         <%=mytime.getB() %>
         <%=mytime.getC() %>
         <%=mytime.getD() %>
         <%=mytime.getE() %>
to present the values on the screen. What I would like to do is assign the object that I create to a javaBean reference declared in a <jsp:useBean> tag as follows:
<jsp:useBean id="test" scope="session" class="calendar.Time" />
        <% CalendarParse sTime = new CalendarParse(); 
            test = sTime.runExample();%>
and then present the values stored in the bean to the JSP page as follows:
<jsp:getProperty name="test" property="a" />
        <jsp:getProperty name="test" property="b" />
        <jsp:getProperty name="test" property="c" />
        <jsp:getProperty name="test" property="d" />
        <jsp:getProperty name="test" property="e" />
        <jsp:getProperty name="test" property="f" />
Is this possible? When I try the above, I get "null" as my output on the screen. When I try the first approach listed above, I get the values I am looking for. Is there a way to accomplish this using the <jsp:useBean> approach?

Thanks to all those who reply.
Sincerely;
Fayyaz
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2008
Added on Sep 17 2008
5 comments
283 views