• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP or Servlets

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What about my question?
 
Randall Twede
Ranch Hand
Posts: 4469
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4469
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic