"Shah, Suneet" wrote:

> Hi
>
> I am new to jsp, but have lots of experience with servlets.  A couple of
> things seem unclear to me and was hoping that some one could help clarify
> them.
>
> I in a typical form processing situation, it is quite common to post the
> form to a servlet, which inturn would do some processing in the doGet/doPost
> methods and the possible redirect to another page.  What is the recommended
> manner in achieving that in jsp, keeping in mind that I would like to
> separate ui from business logic as much as possible (I have seen example
> where you can put in all your java code in the jsp, but that does seem like
> good design)?
>

There is a very natural mechanism to enable this, called request forwarding.  I
design my web applications using exactly the approach you describe:

* Form is created by a JSP page

* Form submit goes to a servlet

* Servlet initiates whatever business processes
  are requested, and synthesizes results in one
  or more beans.

* The beans are stored as attributes of the request
  (if they are only needed for the response I am about
  to generate) or the user's session (if they need to
  last beyond the processing of this request.

* The servlet then forwards control to a JSP page
  that will display the results, possibly based on the
  beans I just passed:

    RequestDispatcher rd =
      getServletContext().getRequestDispatcher("/showResults.jsp");
    rd.forward(request, response);


>
> It seems as though that I can now post into a bean, instead of a servlet.
> By providing matching get/set metthods all my form variables this would be
> done for me.  What happens when I hit the submit button?  Can a method be
> called on that bean that would do the processing and then redirect to
> another page?  A real example of how this works would be great.
>

More precisely, you can POST to a JSP page, which in turn can populate bean
properties based on the parameters included in the POST.  I find that this tempts
you to display the corresponding results in the same page receiving the parameters,
and you can find yourself unwittingly intertwining business logic and presentation
logic to the degree that a change in one (say, a facelift of the web user
interface) requires changes to the other as well.

>
> Thanks in advance.
> Suneet
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to