File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP vs servlets

 
Ritesh Pareek
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in jsp, you cant do something
 
mark benz
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic