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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP or Servlets" Watch "JSP or Servlets" New topic
Author

JSP or Servlets

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Why we should use Servlets not JSP when we are accessing an Application???
Why jsp better than servlets in server side includes?
Preethi Suryam
Ranch Hand

Joined: Nov 17, 2000
Posts: 92
Hi amit!
The basic advantage of JSP over servlets is that it seperates the presentation part from the logical part.
we use "out.println" to include html functionality in servlets.this eliminates that problem.
we can use beans concept in JSP,ie.the reusabilty concept.
when a request comes to HTTP server the servlet(jsp file converted into servlet) is not complied again and again for the same request, so this is time consuming than servlet.
hope u got the answer for ur question.
Preethi.
mike sutton
Greenhorn

Joined: Dec 07, 2000
Posts: 14
I just finished a project using servlets, It was an add to an existing site. The first question from the client was how hard would it be to make this a seperate site and change it's look. Had I known this ahead of time I would have made it using jsp. Oh well lesson learned.
Mike
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
hi Mike,
I did not got what you meant?
Still, I have not got answer to my original question?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Preethi Suryam:
The basic advantage of JSP over servlets is that it seperates the presentation part from the logical part.

Um, no. It does no such thing. JSPs separate presentation and logic no more or less than servlets do.
What JSPs do for you is give the presentation a central place in your source. The logic is embedded in the presentation. In a servlet, the logic is central and the presentation embedded in the logic. Thereby, it becomes obvious when you should choose JSPs over servlets: whenever presentation is more important than logic.
Separation of presentation and logic is quite another matter. It's something YOU have to do, JSPs don't greatly help you there. To the contrary, I would say that the temptation to stick bits of Java logic absolutely everywhere is too great.
It is up to you to implement a clean MVC architecture. The View, then, is purely concerned with presentation and should usually be a JSP. Taglibs can help you get the last bits of logic out of there. The Controller, responding to HTTP requests, is purely concerned with logic and should be driven from a servlet. The Model, finally, is a pure-code affair that is best implemented using Java classes (usually JavaBeans and/or EJBs).

when a request comes to HTTP server the servlet(jsp file converted into servlet) is not complied again and again for the same request, so this is time consuming than servlet.
hope u got the answer for ur question.

I'm not sure what you mean here. JSPs and Servlets don't really differ in performance.
- Peter
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231

What about my question?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

I will try to answer. JSP is basically a html page with java code imbedded(although it gets compiled into a servlet). A servlet is a java program with html imbedded. If you anticipate the look of the pages to change often, JSP is the better choice. If the site is more like an application whos presentation(appearance) is unlikely to change, servlets are easier to write, at least for me, although that could just be lack of practice. SSI would be easier from JSP because in a servlet, the SSI tag is buried in a println statement.
------------------
Dont blindly believe everything I say.


SCJP
Visit my download page
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231

Thanks Randell,
Q1) Can you give me an example of SSI?
Q2) By accessing an application or applet I meant talking with an applet or application. In Sun's JSP tutorials it is mentioned that Servlets can only talk to applets and applications because JSP only deal with textual matter. But I dont believe that. In JSP there is a <jsp lugin> tag with which you can download an applet on the client's browser. Am I correct?
Please help!!!
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

I still need to learn more too.
From what I know of JSP you can use any java code you want. I remember now that SSI is for calling servlets though and the file needs an extension other than JSP, SHTML on some servers. In JSP you dont use SSI you either call a bean or just include the code inside JSP tags.
------------------
Dont blindly believe everything I say.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP or Servlets