This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes best approach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "best approach" Watch "best approach" New topic
Author

best approach

reehan ishaque
Ranch Hand

Joined: Mar 25, 2001
Posts: 54
hi folks!
im new to servlet n jsp.i have done some basic technical stuff both in jsp n servlets. i wanna do some practical work now. so i need little guidence from u ppl.
wat should be the best approach towards development of applications using jsp n servlets. i mean should i go for only servlets, or jsp will be the best approach or mixing them both is better. or it depends wat kinda application im gonna develop. my question seems to be little stupid :d but this is wat confusion is in my mind.
bye
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
quick and dirty advice?
use servlets for doing non visual stuff (you're not outputting HTML) and JSPs for doing purely visual stuff. Try and use beans in your JSP code as much as possible and as few scriptlets as you can manage. Otherwise, it often depends on the problem you are trying to solve. I'll give you the setup for one of my sites,
main site controller is a servlet, it takes URLs decodes them, gets the content and passes all the relevant values to the jsps
#
normal pages on the site, one jsp that includes some html files, and calls two beans to output the menus and the text.
#
response form on the site, servlet (no visual bit)
#
dynamic html editor for the site (administrator) - all jsps with tags.
one last thing to consider - there is one place where I would recommend using java code in jsps: I use them when I develop a part of the site so that I dont have to worry about compiling a servlet. Using jsps I can force reloading without restarting the server, and I dont have to manually compile the code. What I do od though is never mix a jsp that has java code with a jsp that has html in it - my rule to myself is a jsp has either but not both


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
reehan ishaque
Ranch Hand

Joined: Mar 25, 2001
Posts: 54
hi chanoch!
thanx alot for ur reply. one more thing i wanna no is that how to send jsp or html files to the client from servlets. i have seen most of the books written on servlets sendin html through output streams. that seems little miserable. or using methods like sendRedirect(), requestDispatcher() etc..
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
I would use RequestDispatcher.forward(req, res) to forward to a jsp or html page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best approach