Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between servlet and jsp

 
selvi parthu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody,
I have studied servlet and jsp are server side components.
but in MVC architecture,
servlet is used as Controller
jsp is used as view

really I did not get 'why jsp for view'?
please help me.
Thanks in advance
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because for view/display you need to have mix/embed your java output with HTML tags.and doing this in servlet means you have to write lot of out.printlns.And in JSP you can effectively use java code with html tags.Thats why we use JSPs for view.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it's easy to write java logic in Servlet so it is being used as a controller. And it's easy to write HTML code in JSP so it is being used as a view...
 
lakshmi v.samy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
SomeswaraRao Vudattula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is Java code embedded in HTML; the Java code is compiled (if necessary) and run by the container on the server and the client only sees the results of that code's execution mixed in appropriately with the html.

Servlets are compiled pure Java class files (not mixed with HTML) that get posts from the client and send html to in return.

Both require a container on the server, such as Tomcat, which provides the environment and VM for the Java program.
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well JSP is for the "view " because most of the web application the changes are done at the client side and if suppose "Servlet" is used instead of the "JSP". Then the change would take so much time (Coding +compiling + deploying again in web server). This is not effiecient as a result the JSP is responsible to change simultaneously at the client end.

That is why the JSP is works as a "View" and "servlet works as a controller.
Although the "JSP" is automatically converted into the servlet but automatically.

I thinks this would clear you doubt.

Cheers,
Chidanand Chauhan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are done at the client side


This post seems to infer that JSP is processed on the client. This is not the case. JSP is a server-side technology just as servlets are. In fact, JSPs are translated into servlets.

Perhaps this article would be helpful in understanding how JSPs work.

JSP is the preferred technology for view rendition not because it is a client-side technology (it is not), but because it is a better tool for the job. In the same way that a servlet controller is the better tool for non-view processing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic