javabeans, JSP and Servlet


Web tier: servlets, JSP, Web frameworks: javabeans, JSP and Servlet

  1. javabeans, JSP and Servlet (10 messages)

    Hi all,

    I want to create an instance of a java bean and forward it to a jsp page. In the jsp page I want to access the bean. The scope of the bean should be session.
    Can anyone please tell me how to do that?


    Threaded Messages (10)

  2. Hi ,
         U can use the jsp:useBean tag with the scope set to "session". It's that simple.

  3. I am sorry. I forgot to tell u that I want to create a bean instance in a servlet and forward the request to a JSP and access the bean in the jsp
  4. javabeans, JSP and Servlet[ Go to top ]

    Srinivas, try this:

    In your servlet:

    HttpSession session = request.getSession(true);

    In your JSP:

    <jsp:useBean id="theBean" class="..." scope="session"/>
  5. javabeans, JSP and Servlet[ Go to top ]

    Thank U Gordon. I will try that.

    I saw one of the .java file of a JSP and found the following code for the usebean tag

    "<jsp:useBean id="sessionuser" class="Srini.User" scope="session" />".

                    Srini.User sessionuser = null;
                    boolean _jspx_specialsessionuser = false;
                     synchronized (session) {
                        sessionuser= (Srini.User)
                        if ( sessionuser == null ) {
                            _jspx_specialsessionuser = true;
                            try {
                                sessionuser = (Srini.User) Beans.instantiate(this.getClass().getClassLoader(), "Srini.User");
                            } catch (Exception exc) {
                                 throw new ServletException (" Cannot create bean of class "+"Srini.User", exc);
                            pageContext.setAttribute("sessionuser", sessionuser, PageContext.SESSION_SCOPE);
                    if(_jspx_specialsessionuser == true) {
                // end
                // begin [file="C:\\tomcat\\webapps\\examples\\jsp\\srini
  6. javabeans, JSP and Servlet[ Go to top ]

    Thanks Gordon,

    What u suggested is working.

  7. javabeans, JSP and Servlet[ Go to top ]


    Can I share your experience? I confront the same problem. Where did you place your javabean? How to compile it?

    Thanks a lot.
  8. javabeans, JSP and Servlet[ Go to top ]

    What App server you are using?
  9. javabeans, JSP and Servlet[ Go to top ]

    I am using weblogic 6.0. I create a javabean JB (implements serialize)in servlet A:

    JB jb = new JB();
    session.setAttribute("key1", jb);

    In JSP B:
    <jsp:UseBean id="key1" class="" scope="session"/>
    <jsp:getProperty name="key1" property="methodName">

    key1 is not defined as bean
  10. javabeans, JSP and Servlet[ Go to top ]

    Hi MAT,
    I am using Weblogic 5.1. and did not implement J2EE. I put the classes and servlets in weblogic/classes library and the jsp in the docroot public_html.

    Only difference I could find between ur and my code is in the useBean tag. I gave the parameter class="JB".

    I think the probable reason for the error is u did not put the bean in a package.

    Try this out.
    All the best.
  11. javabeans, JSP and Servlet[ Go to top ]

    I have got it. It should be "useBean" case sensitive.

    Thanks a lot anyways.