aspose file tools*
The moose likes Servlets and the fly likes JSP vs servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP vs servlets" Watch "JSP vs servlets" New topic
Author

JSP vs servlets

Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi All,

Java Server Pages is that they are document-centric. Servlets are java programs. JSP is easy to use with equal functionality of servlet. Than MY Question is -- Why to use servlet? Why we can not replace servlet completely? Is there any example that only can be done through servlet (JSP can not able to do that particular task)?

Thanks & Regards

Ritesh Pareek
mark benz
Greenhorn

Joined: Aug 18, 2009
Posts: 15
JSPs can do virtually anything a Servlet can do, because JSPs turn into Servlets.

however JSPs were designed for the 'View' in an 'MVC' design pattern.
usually a Servlet (Controller) contains the business logic (or communicate with Models) and a JSP renders the view to the end user.

Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi Mark,

Thanks for reply.

So, Can we conclude like this?

M - pojo
V - JSP
C - Servlets

Still My doubts are-

1. " Servlets are used for security, you can't impose security level through JSP" , IF you can explain me the meaning of this line.
2. Can we replace servlet completely with JSP? (My question is can we do every thing with JSP that can be done with servlets? )


Thanks & Regards

Ritesh Pareek
mark benz
Greenhorn

Joined: Aug 18, 2009
Posts: 15
So, Can we conclude like this?

M - pojo
V - JSP
C - Servlets

Yes.
Servlets are used for security, you can't impose security level through JSP

What does security mean in this context ?
can we do every thing with JSP that can be done with servlets

I haven't found a situation where using Servlets over JSPs matter. I assume you can.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

in jsp, you cant do something
mark benz
Greenhorn

Joined: Aug 18, 2009
Posts: 15

This is a known issue with JSPs, since outPutStream has already been called.

Interestingly it can be done:

however no blank spaces or characters are allowed before or after the scriptlet.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

mark benz wrote:
Interestingly it can be done:

however no blank spaces or characters are allowed before or after the scriptlet.


i tried this. but i get Exception
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
JSPs can do virtually anything a Servlet can do, because JSPs turn into Servlets.


Imagine an annoying error buzzer noise here.

You have it exactly backwards, servlets can do anything a JSP can do but JSP have built in assumptions that your output is text.

Serving binary information - images, sounds, streaming video, pdf files, whatever is the realm where servlets are essential.

Bill
Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi William Brogden,


Thanks a lot for this valuable reply . Thanks a lot.

I was searching answer of this question for a long time.

Thanks a lot to mark benz and seetharaman venkatasamy.

Ritesh Pareek
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Ritesh Pareek wrote:
So, Can we conclude like this?

M - pojo
V - JSP
C - Servlets



In a model-view-controller framework you almost never code a servlet. That's good. Instead, the MVC framework has a single servlet that acts as a sort of traffic cop, routing requests to a controller you provide. Such controller are usually simple Java classes that, based on the needs of the framework, implement a specified method.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

In modern web applications putting any Java code into a JSP is considered a horrible practice.

Processing code of any kind should be in a servlet (or other Java construct), and only the view should be coded into the JSP using only the JSTL and EL. So there is no JSP versus servlets: JSP and servlets work together to create modern web applications.

Perhaps this article will be helpful.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP vs servlets