Question about using JSP's with Servlets

Discussions

Web tier: servlets, JSP, Web frameworks: Question about using JSP's with Servlets

  1. Question about using JSP's with Servlets (2 messages)

    I have a java servlet which fills a bean. Then, it forwards to a JSP page. Is there anyway I can get the contents of the bean now that the control is on the JSP page? If I create an instance of the bean on the JSP page, it resets the values that were stored in the bean on the servlet page. How can I get around this?
  2. Question about using JSP's with Servlets[ Go to top ]

    In your servlet you can store the data (bean) that the jsp pages will use in the following way:
    request.setAttribute("myData",Data1);

    And then in the JSP, you would access the value by:
    Data1 data1 = (Data1)request.getAttribute("myData);

    For more complex situations, you can store the bean in various scopes lieke ServletContext, HttpSession etc.

  3. if the populated bean is added to request, session..scope
    request.setAttribute("MyBean", Object);
    session.setAttribute("MyBean", Object);

    inside your jsp

    <jsp:useBean ...scope="request/session..." id="MyBean" ..>

    "id" should match with the attribute name.
    the behaviour of usebean is, it first checks for the bean in the scope specified. If it could not be found then creates a new instance of the bean.

    Hope this would help you

    Cheers mate,
    Chandra