Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JSP Vs Servlets?JSP or Servlets

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to make a project
Can anybody throw some light
i should use JSPs or Servlets?
with some advantages and disadvantages
Thanks
 
Saloon Keeper
Posts: 25461
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both. JSPs are better for cases where there is a lot of display activity but little processing, and servlets are better where there's much processing, but little display activity.
Either way you end up with the same results, although on large projects with fancy graphics, it's sometimes useful to let the "art department" generate HTML and then convert the HTML to a JSP.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typically in larger projects you will use Both JSP(JSP is a servlet) and Servlets. What JSP allows you to do though is separate the content display from the java code. You want to separate the HTML and Java as much as possible.
Lets say that you have a page that generates 300 lines of static HTML and in the middle you have a table generated by selections a user has made. If you were to put all of this code into a JSP page you would get a mix of Java and HTML code .. what a mess!! HOw will the HTML designer modify the page with all that java code everywhere PLUS he also has to understand the code. NOt to mention that a year from now if you want to modify the Java code, you will have to remember what all this mess means. Conversely, if you were to put all the content into a Servlet you would be in println hell AND you would still have to insert the dynamic table in there somewhere. In both of the above cases maintainability has been sacrificed and your content designers are pulling their hair out (and maybe yours )
There is a solution though. Put the static content into a JSP page. In this page you stay away from the java code as MUCH as possible ! ! ! Then you script in the dynamic table that comes from a servlet. In this way you have separated the HTML content from the java code and you are light years ahead interms of maintainability. Now when your HTML designers come to modify the page, they dont have to worry about all that java code and will shower you with hugs and kisses .
Ideally you will want to use a combination of the 2 technologies but for smaller projects you may just pick one technology over the other. I would suggest that you use both technologies regardless of the project size. Its a good to keep practicing with both technologies together.... the sum of the whole is greater than the sum of the individual parts.

If you want to know about structure try looking at the struts project at ...
http://jakarta.apache.org/struts/
Start reading now because this will turn out to be an invaluable tool for you. Its, in my opinion, cumbersome to setup at first BUT once setup its a BREEZE to maintain! If you design all your webapps using struts you have standardized the architecture of your projects which makes maintainability a breeze.

My humble opinion of course
[ February 11, 2002: Message edited by: Steven Kors ]
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic