This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Situation like this..

 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can there be any situation where we can only use Servlet & not JSP or vice versa,i.e JSP only & not Servlet.
Hope I am clear
TIA
MB
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.
If all you need is a small number of pages and a few beans, then JSP on its own is great. Likewise, if you don't need fancy HTML generation (or just don't like JSP) then you can build a perfectly reasonable web application only using servlets.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything that can be done in JSPs can be done in servlets and vice versa. However, it can be extremely awkward to use one (such as the example Frank gave with a lot of presentation details.) It can be done with servlets, but it shouldn't.
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank & Jeanne...
Even I was unable to guess any situation like this...also thought in the same way as Frank..If no GUI's has to be made, servlet is the best option, only if we need some sort of HTML stuff to be shown to the users, we would use JSP.
But can anyone guess some specific situation
TIA
MB
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since JSP are designed to output a character stream it is essentially impossible to use JSP to serve binary data such as images. If your application needs to generate images or sounds on the fly, you are going to end up using servlets.
Bill
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it is possible to do almost anything (including generating binary data) with servlets, it is not always a good idea. You could stick whatever code would be in the servlet inside a JSP scriplet. However, this is poor style and should be avoided. But it can be done.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic