Re: form bean and session attribute
Lew wrote:
Not only is 'two.jsp' not required, it's kind of a mistake. You're
using 'two.jsp' to handle logic, i.e., parsing request parameters into a
bean, then forwarding to a .java-sourced servlet to handle display.
Thufir Hawat wrote:
It's basically lifted from:
<http://www.roseindia.net/jsp/jspsession/use-of-form-bean-in-jsp.shtml>
That example isn't following best practices. That whole business with
"continue" is not necessary, and you certainly don't need to put the "form
bean" in the session with a proper architecture, at least not for the way that
site uses it.
I'll ask the question differently, maybe that will help. How do you send
a form bean to a servlet? At some point that view data needs to make its
way to a servlet.
In the first place you don't send a "form bean" in the request, you send
request parameters. The servlet that is the target of the form 'action'
attribute automatically receives those parameters, so just by submitting the
form you are getting them to the servlet.
Use a .java-sourced servlet as the 'action' target, and use the
'HttpServletRequest' object to obtain the parameters and copy them into your bean.
<http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html>
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameterMap()>
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)>
You store the bean in the request context to get it out to the display JSP.
Start here for real information on how to use servlets and JSPs:
<http://courses.coreservlets.com/Course-Materials/csajsp2.html>
Marty Hall is one of the best for this type of information.
Read the document there on the Model-View-Controller (MVC) architecture
<http://courses.coreservlets.com/Course-Materials/pdf/csajsp2/14-MVC.pdf>
and google for more on that topic after you've read it.
You extract a 'RequestDispatcher'
<http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html>
from the request via the 'getRequestDispatcher()' method to handle the
'forward()' to the display JSP.
There's more, but this is a start.
--
Lew