I would like to create a servlet that:
1. does some processing
2. stores the results in a JavaBean
3. forwards to a .jsp
The .jsp page will read the results from the bean and display the formatted results.
How do you instantiate a JavaBean from within a servlet that will be accessible to the jsp? I know how to use the <jsp:useBean> tag to create a bean to share info between .jsp pages.
Here's what I have so far:
(servlet)
..do processing..
MyBean bean = new MyBean();
bean.setTitle = "Title of Document";
bean.setId = "ID of document";
RequestDispatcher dispatcher = getServletContext().
getRequestDispatcher("app/display.jsp"
dispatcher.forward(request,response);
(jsp)
...
<jsp:useBean id="bean"
class="myapp.MyServlet"
scope="session">
title:<br>
<jsp:getProperty name="bean" property="title"><br>
id:<br>
<jsp:getProperty name="bean" property="id"><br>
The display.jsp page displays blanks for all properties. So it must be instantiating a new bean, instead of accessing the one I tried to create in my servlet.
Obviously i'm missing something pretty basic here. Can anyone help?
--dave
1. does some processing
2. stores the results in a JavaBean
3. forwards to a .jsp
The .jsp page will read the results from the bean and display the formatted results.
How do you instantiate a JavaBean from within a servlet that will be accessible to the jsp? I know how to use the <jsp:useBean> tag to create a bean to share info between .jsp pages.
Here's what I have so far:
(servlet)
..do processing..
MyBean bean = new MyBean();
bean.setTitle = "Title of Document";
bean.setId = "ID of document";
RequestDispatcher dispatcher = getServletContext().
getRequestDispatcher("app/display.jsp"
dispatcher.forward(request,response);
(jsp)
...
<jsp:useBean id="bean"
class="myapp.MyServlet"
scope="session">
title:<br>
<jsp:getProperty name="bean" property="title"><br>
id:<br>
<jsp:getProperty name="bean" property="id"><br>
The display.jsp page displays blanks for all properties. So it must be instantiating a new bean, instead of accessing the one I tried to create in my servlet.
Obviously i'm missing something pretty basic here. Can anyone help?
--dave