Robbert, > Christopher Schultz-2 wrote: >> You have your process turned upside down, here. > > Why is the process turned upside down, exactly? Or rather, is there any > benefit in mapping /index to a Servlet and then forwarding to a JSP instead > of going to JSP pages which invoke my Servlet? > This probably boils down to the following question: When do you use a JSP > and when do you use a Servlet?
Well, that's a somewhat philosophical and often religious argument. I think that one ought to use JSPs for quick-and-dirty hacked logic, /or/ for display purposes only. Your "real work" ought to be done in servlets. I find the error handling more straightforward and less messy than in JSPs (although a JSP does get translated into a servlet before execution, so really they are exactly the same thing). At any rate, what you are trying to do is: 1) Perform some logic in your servlet. 2) Emit some output to the client. Since you want to do those 2 things, in that order, why invoke #2 first, which calls-back to #1, and then emits the output? It's far more natural to invoke the servlet and then have it forward to the JSP. Note that this is an internal forward, so the browser has no idea that control has been transferred from the servlet to the JSP. Of course, you could also use an HTTP FORWARD if that's what you really wanted to do. > Struts sounds like a good framework. I'm not too experienced with those but > I take it that won't be hard to use. It's just how we were learned to code. > So it never seemed to me as if the process was reversed. Whether or not you use struts, I highly recommend that you avoid tricks like calling a servlet from a JSP in order to execute your business logic. If you have a waterfall-style logical flow (i.e. execute servlet first, then JSP), it's only natural to have the flow actually do that. It's okay if you application isn't 100% "pull-based" ;) -chris
signature.asc
Description: OpenPGP digital signature