wood burning stoves 2.0*
The moose likes Servlets and the fly likes difference between servlet and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference between servlet and jsp" Watch "difference between servlet and jsp" New topic
Author

difference between servlet and jsp

selvi parthu
Greenhorn

Joined: Feb 02, 2006
Posts: 9
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

Joined: Apr 08, 2005
Posts: 129
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.


"There are no mistakes, only lessons"
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Feb 02, 2006
Posts: 30
Thanks
SomeswaraRao Vudattula
Greenhorn

Joined: Mar 28, 2005
Posts: 12
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

Joined: Nov 10, 2005
Posts: 77
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

Joined: Jan 10, 2002
Posts: 60781
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between servlet and jsp
 
Similar Threads
why to use JSP?
how to call web services in JSP?
clarification reg jsp:invoke, variable directive etc..
response from servlet
forwarding the request ?