• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What's the point of using JSP?

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always make the whole site using Servlet only.
what's the advantage of using JSP and servlet together? Is it just convenience? (don't need to print the html code using out.println)..
I don't know. Please advise.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I see it, there are two advantages
1. It is much easier to do complex HTML with JSP then with lots of print statements.
2. There are so very nice tag libraries including the JSTL that can make life easier.
That said, I usually use servlets too.
Bill
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to learn jsp but seems harder than servlet (?? as i found the scripting of ASP is so strange, don't know if i can handle jsp)

just curious, what's JSTL used for? thanks
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have worked on site which is totally based on servlets as at that time JSP was new.
And it was very difficult to manage HTML codes inside servlets. And then we came to know about JSP. and like you said, initially I also found JSP tougher than Servlets
But now, I always try not to do complex logics in JSP. If there is only Java code, I prefer Servlets but if there is any UI, then I go for JSP. And decide JSP or servlets at design time only. It will really help you.
Render your HTML in Servlets and try to change UI as per your clients requirements thrice a day, you will love JSP
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ken Shamrock:

just curious, what's JSTL used for? thanks


http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=JSTL+&btnG=Google+Search
http://java.sun.com/products/jsp/jstl/
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ravish Kumar
 
tumbleweed and gunslinger
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's generally a good idea not to have "any" java code in JSP files. Check out Struts at:
Struts
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most companies today use ModelII architecture (also known as Model-View-Controller)... The architecture molds the best of JSP, Servlets, beans, etc.
JSP's are basically html pages with java snippets. They were developed to try to keep the separation between html and java. Basically a person who knows html should be able to work on a jsp page since it should be mostly java free. Companies normally have web designers (who work on the look and feel of an app) and java programmers (who work on the how portion). There is a lot of convenience to working with jsp's once you get to the top of the learning curve.
Good luck!
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i read somewhere (am not able to really recall where) that JSPs are auto generated servlets and autogenerated code may not be as efficient (is that the word that was used?? i'm not sure) as we write Servlets by hands.
also, JSP seems better representation when we have html page with various forms and many fields in there to display for which the data is coming from a database...
though there are some architectures like... (oops i again forgot what it is called) where we have code like,
createTable(); // TABLE
createRow(); // TR
createColumn(); // TD
etc methods that helps us to create HTML content without writing HTML tags which makes things easier for us.
guys, sorry for forgetting all the terms on the earth while writing the email :-(
regards
maulin
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Off course, you can have more influence on efficiency writing servlets. But when you enter a web application project which requires (or ever will require) several disciplines, writing servlets for HTML is not the way to go. A (HTML/Javascript) web designer will probably have no idea what to do.
Furthermore, when you are writing complex HTML (with javascript, stylesheets, events and using DHTML) a JSP will give you a much better view on the output of you application.
For understanding JSP pages you need to know:
- directives
- declarations
- expressions
- scriplets
And the objects:
- request
- session
- application
There is more, but this will take you a lot further.....
Hope it helps
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i read somewhere (am not able to really recall where) that JSPs are auto generated servlets and autogenerated code may not be as efficient (is that the word that was used?? i'm not sure) as we write Servlets by hands.

Yes very true, but the key point is, "MAY NOT BE", IMHO, what servlets tomcat generates after conversion is no less than any other servlet written by man.
The only problem I have seen in them that they also send \r, \n characters though its not required. But its a very less price when it comes to GUI maintainace in Servlets

though there are some architectures like... (oops i again forgot what it is called) where we have code like,......

There are ... so are you ready to learn whole new api for a thing which is not your main concern. I mean, I can not design any page. I can give you whatever data you want. when it comes to design, I dont see any diffrence in RED color and BLUE color (I am not color blind )
.....without writing HTML tags which makes things easier for us.
opss.... NOOOOOOOO plz dont mix UI with coding.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ravish,
i was not mixing HTML and UI at all (may be i wanted to say HTML UI). what i meant was,
"if we use such HTML generation API then we don't end up writing those funny and scary escape sequences which make our task easier. we just need to know the 'content' to put in the HTML page". also, the problem with those API, apart from what u already pointed out, is - its a lot just to even write simple HTML Table (we have to use three/four methods..), instead its a lot easier to go in JSP and write HTML for the TAble. again, if we use such APIs then the "only" HTML developer looses the control as he has to know Java.
sure, i agree that JSP is better way to go if we have lot of HTML stuff. but if we have "processing" part more than Servlet is preferrable.
thanks
maulin
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main reason to use jsp (I would never use a servlet for any HTML presentation) as I see it is that someone else can edit them. I can even let my mother (she understands a little html) change the look of a page. That would be impossible to do if it was all servlets.
I usually use model2, using servlets for any java code and jsp for presentation. If you don't, start! It's a little more work in the beginning but it's worth it.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets are really good as controllers especially when it comes to Model II (MVC). From what I've learnt about them so far, I believe that people should never use servlets to output HTML/XML etc. Leave that to JSP because JSP is the view and it is geared towards the UI.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Patrik,
i guess changing the code for JSP is not a concern till somebody is able to upload the code on Production the newer code, right?
i have also the same thought you presented but thats the purpose of JSPs, isn't it? -- "Somebody should be able to change the UI representation w/o having so much knowledge of Java". To avoid lot of Java code in the JSP we use TagLibs etc so that we can make JSPs truely independent upon Java (upto 90% may be)....
well, this discussion can go on and on, you know....we better don't extend it to a length where nobody gets benefitted after investing much of their time as "its always relative choice" to use one or the other thing....
regards
maulin
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well since my dear friend Michael has added his two cents I might as well ad mine. He & I go at this argument all the time. He likes JSPs I LOVE Servlets.
I fully agree, your Java code should not have ONE DROP of html in it & multiple out.println's are just asking for trouble. (BIG Netscape bug) but my approach is a tad different & since I am self employed I have been able to experiment with this.
I lay my HTML out & then strip it down into objects, my servlets then call the objects, passing any required variables (used for shutting off links etc.) I also read webpage content from flat .txt files so ANYONE cam write the articles & not need to know once drop of code. This is also nice for editing on the fly (on the server), you just right click, edit & save)....last but not at all least is the use of String Interfaces for all that cumbersome HTML that gets repeated over & over....I make all of these constants in my interfaces & all of my layout objects implement the interface.
Its not the perfect "end to all" but I have been able to turn my sites into screaming rockets that can be completely redesigned in hours.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just getting into Servlets and JSP but have had issues already and here is what I have found.
I like JSP better.
Forwarding from a servlet causes some difficult issues for the resulting page since its context will be the context to the servlet that forwarded it and not its normal one, thus images and stuff require special handling like root paths. But forwarding between JSP pages does not have this issue(since the forwarding is client side).
In short, JSP pages are better because you can edit them in a HTML editor. Not just that you can edit them, but you can completely manage them. They are just another fancy web page.
I personally don't ever want to spit out HTML from a servlet. I can see no reason for it when a JSP is faster to make and is basically the same thing.
My form data is submitted to servlets of course.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
i am a just a begginer of jsp and servlet,
after over one month learning,i find it is good for me to realize view with jsp,and servlet with the main logics.
at the same time,it is easy to maintaince the web app.
the Model II is so good.as we all know,every thing has two sides.
jsp or servlet ,it it only your decision. :roll:
 
reply
    Bookmark Topic Watch Topic
  • New Topic