tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Jackson" <mjack...@cdi-hq.com>
Subject RE: servlets that forward to other servlets
Date Thu, 23 Jan 2003 18:36:42 GMT
You can always dispatch to another servlet.  You don't have to redirect.

So the sequence could be something like the following:

	-> LoginServlet (validated) (dispatch)-> MainServlet (dispatch)-> *.jsp

It'd look like your page that the MainServlet returned was coming directly
from the LoginServlet, but I'd imagine that'd be ok.

However, in the types of things I've done in the past this sequence isn't
optimal.  What I usually do is valid the login then redirect to the "main".
The "main" will then do a security check, and possibly some business login,
then dispatch to the page that is required.

And really you ought to look at struts.  It's ok not to use it, but the
design pattern that it enforces is really worth looking at (MVC).  It's very
important to learn a good design patterns, the specific framework isn't so
important.  Also, if you want to look at design from the perspective of bad
designs, I'd look at the book "Bitter Java".  You can d/l a pdf of the book
at www.theserverside.com

--mikej
-=-----
mike jackson
mjackson@cdi-hq.com

> -----Original Message-----
> From: Erik Price [mailto:eprice@ptc.com]
> Sent: Thursday, January 23, 2003 10:19 AM
> To: Tomcat Users List
> Subject: Re: servlets that forward to other servlets
>
>
>
>
> Shapira, Yoav wrote:
> > Hi,
> > If it were a universal bad idea, it probably wouldn't be available as an
> > options ;)  Although that may just be wishful thinking on my part.
> >
> > It's not always a bad idea.  As usual, if you share your design and give
> > some more concrete details, we may be able to help more.
>
> Good point -- here's the scenario:
>
> My initial design was to have servlets perform all processing of user
> input, and each servlet redirects to a JSP to display the HTML to the
> user.  Unfortunately, I've found that sendRedirect() is not sufficient,
> since complex objects cannot easily be sent to the JSP as HTTP
> parameters.  Thus, I've decided to use
> getRequestDispatcher(some.jsp).forward() instead of sendRedirect(),
> since I can refer back to a complex object set in the servlet from the
> "receiving" JSP.
>
> The only problem is that sometimes a servlet needs to forward to another
> servlet, for instance LoginServlet needs to forward to MainServlet.
> Most of the time, the user is already logged in and so does not need to
> use LoginServlet at all, but the first time they enter the application
> they will need to confront LoginServlet before confronting MainServlet.
>   So LoginServlet will need to forward to MainServlet, yada yada.
>
> > If you're
> > getting into a lot of request dispatchers, perhaps you should
> > investigate a framework like struts.
>
> I have no experience with struts, but everyone keeps talking about it.
> It seems worth learning, but I thought I'd try to write one complete
> basic webapp using only JSP + servlets first before going on to learn
> any frameworks, just for the sake of learning and so that I'd appreciate
> a proper framework more when someday I do use one.
>
>
> Thanks,
>
> Erik
>
>
> --
> To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message