Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Choice between JSP and Servlet

Reply
Thread Tools

Choice between JSP and Servlet

 
 
Matt
Guest
Posts: n/a
 
      06-12-2004
I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
eventually. But in application development's standpoint, anything can be
done in servlet can also be done in JSP? Some people told me we can
use the combination of both in one application.

My question is in what situation we use JSP alone, servlet alone, or
combination of both??

Please advise. Thanks!!
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      06-12-2004
Matt wrote:
> I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
> eventually. But in application development's standpoint, anything can be
> done in servlet can also be done in JSP? Some people told me we can
> use the combination of both in one application.
>
> My question is in what situation we use JSP alone, servlet alone, or
> combination of both??


Sure, you can incorporate Java code directly into a JSP. But it breaks
one of the cardinal rules, and the reason for the existence of JSP in
the first place.
What you should be trying to do is cleanly separate Java code from
HTML. Use tags in your JSP to access underlying functionality. Don't
use servlets to generate HTML.
Do yourself a favour and don't fall into the trap of trying to do it
all in a JSP while promising that you'll separate things once you're
ready to go live. You'll run out of time and maintenance will become
an absolute nightmare!
Do it right the first time.

 
Reply With Quote
 
 
 
 
William Brogden
Guest
Posts: n/a
 
      06-12-2004
On 11 Jun 2004 22:28:48 -0700, Matt <> wrote:

> I am new to JSP and Servlet. I know JSP container will convert JSP to
> servlet
> eventually. But in application development's standpoint, anything can be
> done in servlet can also be done in JSP? Some people told me we can
> use the combination of both in one application.
>
> My question is in what situation we use JSP alone, servlet alone, or
> combination of both??
>
> Please advise. Thanks!!


The usual response to this question is:

Use JSP where the complexity of the HTML is the most important
thing / or where non-programmer HTML authors have to maintain the
site.

Use servlets where computation is the most important thing or
where binary content such as images must be generated.

Many people happily use a mixture.

Bill

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-13-2004

"Sudsy" <> wrote in message
news:...
> Matt wrote:
> > I am new to JSP and Servlet. I know JSP container will convert JSP to

servlet
> > eventually. But in application development's standpoint, anything can be
> > done in servlet can also be done in JSP? Some people told me we can
> > use the combination of both in one application.
> >
> > My question is in what situation we use JSP alone, servlet alone, or
> > combination of both??

>
> Sure, you can incorporate Java code directly into a JSP. But it breaks
> one of the cardinal rules, and the reason for the existence of JSP in
> the first place.
> What you should be trying to do is cleanly separate Java code from
> HTML. Use tags in your JSP to access underlying functionality. Don't
> use servlets to generate HTML.
> Do yourself a favour and don't fall into the trap of trying to do it
> all in a JSP while promising that you'll separate things once you're
> ready to go live. You'll run out of time and maintenance will become
> an absolute nightmare!
> Do it right the first time.
>

I'm new to jsp myself and am interested, therefore, as an observer.
Is it true that the technique to do the separation is to make java beans?
Then the jsp pages can interact with the java stuff via the bean properties?


 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      06-13-2004
Liz wrote:
<snip>
>>Do it right the first time.
>>

>
> I'm new to jsp myself and am interested, therefore, as an observer.
> Is it true that the technique to do the separation is to make java beans?
> Then the jsp pages can interact with the java stuff via the bean properties?


That's the proper approach, IMHO. The tags (custom or Struts or JSTL)
create scripting variables which adhere to the semantics of JavaBeans,
i.e. they provide accessors/mutators named getXXX/setXXX (where XXX is
the property name).
Pay particular attention to the javax.servlet.jsp.tagext.TagExtraInfo
class. Note that the norm is a tag similar to this:
<taglibURI:tagName id="..." name="..." property="...">
The bean specified by the name attribute is located and the getXXX
method is invoked using the value of the property attribute to replace
XXX. Finally, the returned Object is placed into page scope under the
name specified by the id attribute.
If you want to read an excellent treatise on the power of JSPs and
custom tags then I highly recommend "Advanced JavaServer Pages" by
David M. Geary, ISBN 0-13-030704-1. His region tag library was the
progenitor of Tiles.
Once you see how straight-forward it can be to "do it right", you'll
steer clear of the quagmire of scriptlets and other nasties.

 
Reply With Quote
 
juli
Guest
Posts: n/a
 
      06-16-2004
hai readers,

I think servlets stuff should be learnt first since writing jsp alone will
not make a web development scalable i mean u should embed custom tag from
jsp in to servlets or servlets will looklike html pages wtih less coding
ie programming logics.

Once u get thru servlets +jsp deploy the same application in ejb it will
be perfect scalable application

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening new child window - Running servlet (JSP and Servlet) agapitolw@yahoo.es Java 4 08-27-2007 12:57 PM
Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response javadev Java 5 11-16-2006 11:22 AM
communication between JSP and Servlet Garg Java 0 11-14-2006 06:19 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57