Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp vs servlets

 
java Bhoy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JSP...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Umm, yeah... just so there's no confusion, that's pretty what what Stan said.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic