File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP Vs Servlets?JSP or Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Vs Servlets?JSP or Servlets" Watch "JSP Vs Servlets?JSP or Servlets" New topic
Author

JSP Vs Servlets?JSP or Servlets

Sunil K Bansal
Ranch Hand

Joined: Jan 04, 2001
Posts: 62
I have to make a project
Can anybody throw some light
i should use JSPs or Servlets?
with some advantages and disadvantages
Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Steven Kors
Ranch Hand

Joined: Jan 30, 2002
Posts: 33
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 ]

Thanks,
Steven
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Vs Servlets?JSP or Servlets