wood burning stoves 2.0*
The moose likes JSP and the fly likes jsp vs servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp vs servlets" Watch "jsp vs servlets" New topic
Author

jsp vs servlets

java Bhoy
Greenhorn

Joined: Feb 22, 2004
Posts: 1
hope im in the right forum...
i do code some applications in java .. and wanted to do some upgrades into doing some jsp or servlets ...
but first thing before diving into the ocean .. what are the pros and cons of both.. what is the differences of the two and lastly how about considering applets???
any lights to shed on me... thanks in advance
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You might want to wander up the page to the Servlet and JSP forums (forae?) for this topic. In short, Servlets are pure Java code. Most people nowadays like to use them to receive incoming GET or POST requests from a browser. JSPs look like HTML with some Java or tags here and there, and work well for generating the response that goes back to the browser. There are frameworks like Struts that formalize these rules nicely. Sun has a J2EE patterns page that talks about this stuff (plus much more about EJB).
Here's how most of them work:
Browser -> Servlet : GET URL or POST form
Servlet looks at the request and picks a handler. The system I'm working on now has an "ActionID" on every request, and that maps to a Java Handler class.
Servlet -> Handler : Handle this request
Handler -> Business objects : call appropriate methods, return some interesting data
Handler stuffs the data on the Session
Handler returns to Servlet.
Servlet figures out what page to show next. This might be mapped from ActionID again, or the Handler might have specified a page.
Servlet forwards to a JSP page.
JSP page gets the data from the Session and generates HTML.
Sun Patterns Page - follow the "catalog" link.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving to JSP...


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Welcome to the Ranch "java Bhoy"!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

The only thing I'd add to Stan's reply is that it is usually not recommended to put data onto the session unless it needs to persist beyond the scope of the current request. It's much more common (and preferred) to use the request scope to 'pass' data from the controller servlet to the JSP page unless usch persistance is necessary.
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
cleaner design for large projects:
1) Servlet as controller which invokes the services based on incoming request.
2) JSP just for rendering purposes(including some level of using server side parameters etc).
Dan.


Kishore
SCJP, blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Umm, yeah... just so there's no confusion, that's pretty what what Stan said.
 
 
subject: jsp vs servlets
 
Similar Threads
question about BMP/CMP to view??
Differenct between Servlet ans JSP?
IllegalStateException
some questions
Display Java Method Result in JSP