• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why cannot use view in Servlets?Why we go for View in jsp?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have small doubt.
In MVC,View Why We go for JSP.
Controller Why we go for Servlets.

why can not do exchage to use these two's?

both r doing similar functionalities.

what is reason give me brief details.

Regards
Shiryans Nath
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why wouldn't you want to use them this way?

A servlet is laid out perfectly to handle the control flow in a web programming evironment. It's method names make everything very self evident.
Building the output stream, however, is cumbersome in a servlet.
It involves typing 'out.println' over and over again.

JSP (especially now, with EL and JSTL) makes it possible for people with design skills but no understanding of Java to focus on look and feel in an evironment almost as simple as plain HTML pages. Controlling the flow, however, is cumbersome as all of the underlying servlet structure has been abstracted and buried in order to hide it and simplify things for those only concerned with appearance.
[ May 16, 2005: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think Ben is right

i go with ben, servlets and JSP are going very fine in their ways.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the best answer I can give to a question like this is to advise you to try coding your webapp by putting all of your presentation logic into servlet code rather than a JSP. Then, you'll realize very quickly why we use JSPs.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some teams in my shop have these rules: Servlets are pure Java, no HTML and no output to the browser. JSPs are pure HTML and tags, no Java. This works out nicely with a Servlet controller, JSP view design.

No Java in JSP is pretty harsh, but if you can really do it the JSPs are much cleaner. My own project inherited a framework and architecture that uses Java in JSPs and it is painful at best. Given the chance, I'd adopt these rules next time around myself.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More straight, a JSP is just for rendering the view, on the other hand Servlet works as a controller. Bottomline is, vice versa is a SIN.

If you really want to see the punishment for this sin. Please do the experiment, however James has already invited you. Try it out and you will know.

You can look at JSTL, EL, and custom tag features. These are the evidences that java code in JSP is highly discouraged.
reply
    Bookmark Topic Watch Topic
  • New Topic