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.
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
Joined: Jan 23, 2002
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)
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
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
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!
-Mike Destefano<br />"Sometimes you feel like a nut..."
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
"...you've got to ask yourself one question, Do I feel lucky?"
R K Singh
Joined: Oct 15, 2001
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.
Joined: Nov 04, 2001
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
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.
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.
In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Joined: Nov 04, 2001
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
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.
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.
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:
Nice to meet you here.<br />I will learn from you.