Servlets and JSP

S

Sameer

I am new to J2EE technology.
Is it necessary to learn Servlets as JSP is more simple to learn than
Servlets?
Why one should write println statements and compose html if same can be
done easily usiing tags in JSP?
Are there any advantages of Servlets over JSP?
Please brainwash.
 
M

murali.k

Hi Sameer!

JSP is the extension of Servlet technology. In JSPs the seperation of
business logic to presentation logic is very clear where as in servlets
its not.

And when it comes to your question, depending on your architecture you
can prefer servlets or JSPs. For suppose if you are using MVC
architecture, the recommended components are View as JSP, Controller as
Servlet and Model as EJB or a simple java class.

If you think of JSP's it will compile as a servlet only. So there is
no much differece if you really see in JSP and servlets. The only thing
is based on requirement which one you will prefer.

If you can write JSP's very well, and in your architecture there is no
need of servelets then no need for you to learn servlets. But i feel,
if you know the JSP technology it is very easy to learn servlets also.
 
C

chris brat

Its generally a bad idea to generate your HTML code in the servlet
itself - this is very error prone and difficult to debug.

Rather use a servlet or servlets to perform the "Control" in a MVC
pattern and use the JSPs for your "View" (i.e. what the user sees).

The two technologies complement each other and its a good idea to have
an understanding of both.
 
S

Sameer

Thanks!
I got a new word MVC related to J2EE.
I will study about MVC and may learn both Servlets and JSP.
 
R

Raghavan alias Saravanan M

Hi Sameer,

Servlets and JSP are both the technologies used in the J2EE Web
application. An one line difference would be, "In Servlets you can
embed html code with java so as to display something in the browser; in
JSP, you embed java code along with html code so as to have your
decision making with logics".

But then writing html code in java is having much overheads thereby
the servlets for display purpose is not suggestable and not preferred.
same way mixing java code and handling the business logic is not
preferred as the main intention of the technologies are not saved (jsp
- just for presentation).

Thereby its suggested that the best use of these two technologies
can be achieved by making use of Servlets - as the Controllers
(decision making and delegating (handing over) the request to the
appropriate resources to handle the request efficiently) and the JSP as
just the presentation (to display the output). => this is nothing but
MVC-2 Architecture.

In the middle the data which is being operated upon is nothing but a
bean (POJO Object preferably). [you may extend it to the data in the
database being handled in the layer called DAO but it is certainly out
of context as per your question now].

Servlets are nothing but the extension of a web server. A Server Side
Java based technology which deals with API (Application Programming
Interfaces - to put in a raw term - methods or functions) which are
maintained by an engine called Servlet Container which in turn runs in
a Web Server. You can learn it easily. If you learn Servlets, JSP is
very easy, as every jsp is getting converted into a servlet after
getting compiled. On JSP's perspective you just need to learn a very
few things only.

You are welcome for any further questions/clarifications.

Good luck,
Raghavan alias Saravanan M.
 
D

dingbat

Raghavan said:
Servlets and JSP are both the technologies used in the J2EE Web
application. An one line difference would be, "In Servlets you can
embed html code with java so as to display something in the browser; in
JSP, you embed java code along with html code so as to have your
decision making with logics".

Please, no!

This is almost entirely backwards (it's a popular technique, but it's
rubbish code)

Try this:

"In Servlets you write Java code to implement logical decision making.
You can possibly generate HTML code here, but it's tedious to author it
and not recommended.

In JSP, you write HTML with Java embedded it, so as to have easy HTML
authoring and also access to the results of Java code. Good JSP has a
minimum of either Java code or control logic directly embedded in it.
Keeping JSPs free of Java can be assisted by using Tag Libraries.
Keeping control logic out of JSP can be done by keeping it in separate
Servlets and using an MVC pattern."

But then writing html code in java is having much overheads

Why? Do you understand how JSP is compiled before execution?


The later part of your post is broadly correct, but you'd already
confused the poor reader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top