This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes This weeks giveaway : Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "This weeks giveaway : "JSP Examples and Best Practices"." Watch "This weeks giveaway : "JSP Examples and Best Practices"." New topic
Author

This weeks giveaway : "JSP Examples and Best Practices".

Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
This week we are giving away 4 copys of the book :"JSP Examples and Best Practices".
The best part, the Author, Andrew Patzer, will be online to answer your questions!
Let's all give him a warm JavaRanch Welcome!
Thanks to the people at APress for the book's!
Murilo Beriam
Greenhorn

Joined: Jul 16, 2002
Posts: 6
Hi guys! I'd like to know which is the best way to ensure security in an action of a form. We should garantee the method used (POST or GET)? Is there any manner to avoid the user to copy the form to his machine and alter some code before submitting?
Thanks a lot!
mary sarami
Greenhorn

Joined: Feb 11, 2001
Posts: 25
I have read some reviews on this book, and even though I have accumulated many JSP books, this book it what I am looking for. We are in the final stages of the first release of a web site that uses JSP and servlets and I would like to read up on "best practices and design principles", as well as open source testing tools to validate JSP-based Web applications.
Our next release will include secure and non secure web pages. Would Model-View-Controller (MVC) be a good option for this? We have to display a different header, side nav and footer depending on if secure or not.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi Andrew,
welcome to javaranch.
I never thought I would consider buying (or winning ) yet another JSP book, but this looks really interesting.
What I am missing on the amazon page about the book is the word "struts". Don't you like the struts-framework?
The focus on the process of development with unit-testing, automated build procedures etc. is really an important topic and for me the main consider-buy-this-one-too argument.
Ren Li
Ranch Hand

Joined: Feb 20, 2002
Posts: 64
Welcome Andrew,
Same as Axel, I am looking for the key words "struts" and "taglib" too.
Maria Tan
Greenhorn

Joined: Jun 24, 2002
Posts: 25
Welcome to javaranch, Andrew.
We would like to use (MVC) model-view-controller in our next release. I would like to understand it more deeply.
Sandep Chaturvedi
Ranch Hand

Joined: Aug 20, 2002
Posts: 49
From what I read in the book summary, it covers design patterns and other aspects of JSP other than the cool stuff you can do in scriptlet (like a magic JSP). I hope your book open the eyes of JSP developers and make them better programmers -- Atleast better than ASP developers
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
I checked the synopsis of the book on Amazon.
It says you do talk about Apache tools in your book. Are there lots of examples of Ant Build files?
Do you use JUnit for your unit testing? Are there examples of that as well? Do you talk about other testing tools like Cactus or Cruise Control?
It also says you talk about MVC architecture - do you use or talk about Struts in the book? If you do, are there examples?


Greg Ostravich - SCPJ2
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Well, thank you for the warm welcome. I look forward to discussing JSP with all of you over the next few days. This thread has hit upon a few different questions, so I'll try and cover each one here. If I miss anything, please start a new thread and I'll try and address it there.
Regarding the questions about MVC -- I believe that using a model view controller framework is by far the best way to approach web development. It allows not only for reuse of key components, but it also gives you a very flexible 'plug-n-play' architecture that allows you to insert functionality into the request stream. For example, let's say you need to check the HTTP headers and modify the request prior to executing it's target. If you're using an MVC framework, it's easy to insert the a call to that custom functionality either inside the controller, or even as a servlet filter before the request even gets to the controller.
Regarding Struts -- I do like the Struts framework and I even use it on my current project. If you are willing to take the time to learn it, then I believe it can provide a lot of value. My book does not address Struts for two reasons. First, there are other books covering struts much better than I could (J2EE Frontend Technologies - Jorelid). Second, I thought that designing and building a custom framework was a good way to illustrate the use of the design patterns discussed in the book along with several other architectural best practices like unit testing and automated build procedures.
Tag libraries -- I devoted an entire chapter to tag libraries. I also cover them later in more depth when discussing the View-Helper design pattern.
A note about the coverage of unit testing in the book -- I included it as a best practice, but I do not get into as much detail as some may be looking for. I cover the basics of using JUnit and specifically how to use JUnit to test the framework we build throughout the book.
I hope this answers all the questions in this thread. If not, please start a new thread and I'll do my best to address it.
Thanks!
Andrew


Andrew Patzer<br /> <br />Author of: <br /> <br /><a href="http://www.amazon.com/exec/obidos/ASIN/1590590201/ref=ase_electricporkchop/103-9402848-9855031" target="_blank" rel="nofollow">JSP Examples and Best Practices</a><br /> <br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1590594118/qid=1109107718/sr=1-7/ref=sr_1_7/104-5148852-3564711?v=glance&s=books" target="_blank" rel="nofollow">Foundations of JSP Design Patterns</a>
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Looks like another question slipped in there while I was posting my reply.
I do cover some of the apache tools. I think the Apache Jakarta project is the best thing to happen to both Java and Open Source. That being said, don't look for extensive coverage of any of the Jakarta tools, but rather a brief introduction and then a specific application of the tool as it fits in the context of the book.
I do provide examples of using Ant to do the following:
- Integrate with CVS
- Copy files
- Compile source code
- Create JAR files
- Build WAR files
- Check OS and conditionally execute targets
Andrew
Venkat Kulkarni
Greenhorn

Joined: Jun 04, 2002
Posts: 15
How do I participate in the "Giveaway"s ?


Senior Programmer Analyst, American Management Systems Inc.
SCJP For Java 2, eBiz+ Certified Professional, SCWCD For Java 2, PMP
Sandep Chaturvedi
Ranch Hand

Joined: Aug 20, 2002
Posts: 49
what version of Ant have you used in the book. with version 1.5, there is a manifest tag which solves many of class loader miseries we face.
Ruilin Yang
Ranch Hand

Joined: Jan 06, 2002
Posts: 150
I used Java beans a lots in my JSP programming. I have not used much of the tags. I feel it is quite good way to separate presentation from data by using java beans.
Would you please give some comments on the merit of using tags versus using java beans in JSP?
Thanks
Ruilin
[ August 27, 2002: Message edited by: Ruilin Yang ]
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
Originally posted by Andrew Patzer:
Regarding the questions about MVC -- I believe that using a model view controller framework is by far the best way to approach web development. It allows not only for reuse of key components, but it also gives you a very flexible 'plug-n-play' architecture that allows you to insert functionality into the request stream.

Are you a strict Type II MVC adherent? Also, what is your take on the choice between directly accessing model objects (read-only) from JSPs rather than a servlet building a collection of dataset results from the model and passing generic collections back to the view (JSP) using request.setAttribute()? Last, should JSPs *ever* be posted to? Or should you always post to a servlet and have it load the JSP, even if the servlet doesn't do anything else?
Thanks!


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
Daniel Ng
Greenhorn

Joined: Jul 09, 2002
Posts: 27
Does this book come with a CD with all the examples?
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Welcome Andrew! Enjoy your "stay" at the ranch.
Janet
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Gerry Giese:

Are you a strict Type II MVC adherent? Also, what is your take on the choice between directly accessing model objects (read-only) from JSPs rather than a servlet building a collection of dataset results from the model and passing generic collections back to the view (JSP) using request.setAttribute()? Last, should JSPs *ever* be posted to? Or should you always post to a servlet and have it load the JSP, even if the servlet doesn't do anything else?
Thanks!


I am pretty strict when it comes to MVC and I do advocate a Type II model to JSP/Servlet development. I understand some situations may not call for it, but I find that most situations can benefit from it.
I do access model objects directly from JSP's. My controller servlet calls an action object, which generates a JavaBean (model), then adds the bean to the request attributes, and forwards the user to a specific JSP. The JSP then grabs the bean and uses it. I think this is a clean approach, but I can't say for sure that it's the best one. It's just the way I prefer to do it.
Posting data to a JSP is okay on the surface, but I believe you're better off posting to a servlet and then forwarding the user to the JSP. I'd rather go through the extra effort involved to obtain a clean separation of model data from presentation code. As you extend the application, you'll begin to see the benefits of using MVC rather than posting to a JSP (reuse, extensibility, maintainability, etc...)
Thanks for the questions.
Andrew
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Daniel Ng:
Does this book come with a CD with all the examples?

No CD, but you can download all the examples from the Apress website.
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Janet Wilson:
Welcome Andrew! Enjoy your "stay" at the ranch.
Janet

Thanks! I'm glad to be here. I always enjoy exchanging ideas with fellow developers. No matter how much anyone thinks they know, I think you can always learn something from everyone.
Kees Pieters
Greenhorn

Joined: Aug 14, 2002
Posts: 9
Do you recommend this book for a JSP newbie?
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by keesp:
Do you recommend this book for a JSP newbie?

Absolutely. The first part covers all the basics you need before diving into the really good stuff like design patterns and framework development. You may wish to pick up a different JSP book to supplement this one if you're totally new to JSP, but either way this book will help you by starting you out on the right path with good design skills.
Andrew
kevin_liu
Greenhorn

Joined: Aug 22, 2002
Posts: 5
Hi, Andrew, Glad to meet you here.
I am preparing for the Sun Certified Java Web Component exam right now. By your point of view, how will this book help me on that?
thanks!
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
Originally posted by Andrew Patzer:
I am pretty strict when it comes to MVC and I do advocate a Type II model to JSP/Servlet development. I understand some situations may not call for it, but I find that most situations can benefit from it.
I do access model objects directly from JSP's. My controller servlet calls an action object, which generates a JavaBean (model), then adds the bean to the request attributes, and forwards the user to a specific JSP. The JSP then grabs the bean and uses it. I think this is a clean approach, but I can't say for sure that it's the best one. It's just the way I prefer to do it.

In my situation I've got a set of objects that I'm keeping in session because they get modified as the user visits various pages (save doesn't happen until a 'submit report' event occurs at the end of the session). They are not specifically JavaBeans but they are 'model' objects in that they handle database interaction, data storage, business rules, and provide gettors/settors. Is it not OK to just get the objects out of session and call the gettors from JSP? That was part of my question. Why go through the overhead of building a bunch of new generic objects to place in the request when you can access the model object out of session directly and call it's gettors?
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Gerry Giese:

In my situation I've got a set of objects that I'm keeping in session because they get modified as the user visits various pages (save doesn't happen until a 'submit report' event occurs at the end of the session). They are not specifically JavaBeans but they are 'model' objects in that they handle database interaction, data storage, business rules, and provide gettors/settors. Is it not OK to just get the objects out of session and call the gettors from JSP? That was part of my question. Why go through the overhead of building a bunch of new generic objects to place in the request when you can access the model object out of session directly and call it's gettors?


Your approach is not necessarily a bad one, but you are opening yourself up to maintenance headaches by combining model data with business logic, navigation, and database code. Using an MVC approach is not that much work and it really makes more sense than doing a page-to-page solution.
John Mallavalli
Ranch Hand

Joined: Apr 24, 2002
Posts: 46
Hi Andrew,
Welcome to the Ranch!!
The info on the book which you have given so far really drives me to get the book rightaway.
The various features that you had outlined are really worthy and hard to find in common.
Congrats on the great job.
One question which I would like to ask you now is:
What are the typical cases where one would go for the MVC architecture or rather what are the main issues which really compel the programmers to use the MVC architecture?
Regards,
John


Do not let what you cannot do interfere with what you can do !!<br /> <br />SCJP & SCWCD 1.4
sridhar satuloori
Ranch Hand

Joined: Nov 05, 2001
Posts: 144
Andrew,
Does this book contains any information on how to build JSP compiler
--Sridhar
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Andrew,
does your book covers the topic of clean separation between JSP/Servlet - code and business logic and database interaction.
A for me quite dificult design issue is to really let the the jsp/servlets (or more precisely struts-action classes) interact with true business objects which could be reused for say a swing -interface.
And have these business-objects separated from an database-interaction interface so that I could easily substitute different datasources (rdbms, xml, object-relational mapper, lotus-notes).
Or is this out-of-topic regarding your book?
Axel
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by John Vijay:
Hi Andrew,
Welcome to the Ranch!!
The info on the book which you have given so far really drives me to get the book rightaway.
The various features that you had outlined are really worthy and hard to find in common.
Congrats on the great job.
One question which I would like to ask you now is:
What are the typical cases where one would go for the MVC architecture or rather what are the main issues which really compel the programmers to use the MVC architecture?
Regards,
John


Hi John,
The MVC architecture is applicable to just about any web application involving a series of data collection, or other type of interaction with an end user. The MVC approach creates a clean separation of layers that allows you to plug in common functionality without having to duplicate code across pages. It gives you the ability to inspect and modify the request and response outside of the actual business logic being performed.
I think the 'core' of my book really deals with using MVC to create a request-handling framework similar to Struts (without all the extras that Struts provides).
Andrew
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by sridhar satuloori:
Andrew,
Does this book contains any information on how to build JSP compiler
--Sridhar

No, this book doesn't dive into that level of detail. Offhand, I can't think of where you'd find such information.
Andrew
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Axel Janssen:
Andrew,
does your book covers the topic of clean separation between JSP/Servlet - code and business logic and database interaction.
A for me quite dificult design issue is to really let the the jsp/servlets (or more precisely struts-action classes) interact with true business objects which could be reused for say a swing -interface.
And have these business-objects separated from an database-interaction interface so that I could easily substitute different datasources (rdbms, xml, object-relational mapper, lotus-notes).
Or is this out-of-topic regarding your book?
Axel


Yes, my book does cover this level of separation. In fact, the main message I'm trying to get across with this book is that you should try to achieve this level of separation rather than taking the original 'JSP Model 1' approach and stuffing all of your code inside the JSP's.
As for the interaction with neutral business objects from within your web framework, my book develops a framework that allows for this, but this topic is not discussed at length. Inside your action classes (in Struts or the framework I develop in the book), it is desirable to import your business objects and interact with them as they pertain to your web application. These objects can then be reused in a similar manner for a Swing app, or even a J2ME app.
Andrew
Roy Cantos
Ranch Hand

Joined: Feb 22, 2002
Posts: 38
Can i use the JSP Examples and Best Practices as a reference for SCWCD exam?, does it cover the objectives?
Thanks
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Hello Andrew,
I have a question regarding best practices, but first, I want to explain my personal take on the subject.
I have eliminated scriptlets from my jsp's for several reasons.
- scriptlets do not promote reusability
- scriplets require more maintenance
- scriptlets require bulk-page editing.
- scriptlets make page maintenance difficult
How do you feel about using scriptlets in css files? It is something that i have considered doing with custom tags, but I found that it is easier and even cleaner to do this with scriptlets.
I have three things that I have used scriptlets for within css files. The most basic is browser detection. It is a well-known fact that no two browers handle css exactly the same. Since the css file is a template file, I feel that it is most appropriate to use scriptlets. The template can be modified with little effort and a the entire site can be updated with that.
What's your take on this?
(I want your book)
Garrett


comp.lang.javascript FAQ: http://jibbering.com/faq/
Sandep Chaturvedi
Ranch Hand

Joined: Aug 20, 2002
Posts: 49
I have used scriptlet in css. Just one point of caution: css is loaded as a seperate request. If you introduce scriptlet there then it will not get cached and increase network traffic.
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Garrett Smith:
Hello Andrew,
I have a question regarding best practices, but first, I want to explain my personal take on the subject.
I have eliminated scriptlets from my jsp's for several reasons.
- scriptlets do not promote reusability
- scriplets require more maintenance
- scriptlets require bulk-page editing.
- scriptlets make page maintenance difficult
How do you feel about using scriptlets in css files? It is something that i have considered doing with custom tags, but I found that it is easier and even cleaner to do this with scriptlets.
I have three things that I have used scriptlets for within css files. The most basic is browser detection. It is a well-known fact that no two browers handle css exactly the same. Since the css file is a template file, I feel that it is most appropriate to use scriptlets. The template can be modified with little effort and a the entire site can be updated with that.
What's your take on this?
(I want your book)
Garrett


Hello,
I'm afraid I don't have any experience loading scriptlets inside of CSS files. I will say, however, that page scripting is well suited for any kind of browser interaction. Custom tags and JavaBeans are suited more for model data and presentation logic (ie. adapting the model to the presentation). So, my feeling on the subject is that it is okay to use scripting inside your pages for any kind of browser interaction, but not necessarily for application-specific logic.
Andrew
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Hi Andrew,
goooood to meet you here!!!
This post comes from Serbia-Yugoslavia.
There are not so many translated books on Java in my country, and the only one dealing with JSP is: "Java Developers Guide to E-Commerce with XML and JSP".
I bought that book, and I'm not phrentic. The other book I read is "Core servlets and JSP". This one is close to what I was looking for.
I'm looking forward to introduce and educate my friends in Java technology - especially servlets and JSP in order to show and prove them that this is better solution than C#.
I'm especially interested in ypur guidelines and tips when implementing MVC.

Enjoy your "stay" at the ranch.
Peter W Smith
Greenhorn

Joined: Aug 28, 2002
Posts: 10
Andrew,
My friend bought your book and I read the first few chapters. I was glad to know I "invented" almost the same techniques for page navigation, error checking, etc. After finishing those chapters, I'm assured that my approaches were industry-strengthy.
However, I'd like to know more about how other people do logging and monitoring with web apps. specifically (but not completely), logging should happen at which points with what data, level? how to combine logging with sending error page back to user? how should logging of error tigger notification to administrators? etc.
I feel my approaches to the above is good, but need to confirm.
BTW, I want to have my own copy of your book, and for FREE
thanks
Rajeev Nair
Ranch Hand

Joined: Mar 11, 2002
Posts: 51
Andrew,
What Web container or Web Server you deal in your book ?. I have Tomcat loaded and will that be OK to run the examples from your book.
Do you have any sample chapters to look at?.


Raj<br />Sun Certified Java Programmer
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68
Andrew,
How long did it take you to write this book? Could you tell us your background?
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Velika Srbija:
Hi Andrew,
goooood to meet you here!!!
This post comes from Serbia-Yugoslavia.
There are not so many translated books on Java in my country, and the only one dealing with JSP is: "Java Developers Guide to E-Commerce with XML and JSP".
I bought that book, and I'm not phrentic. The other book I read is "Core servlets and JSP". This one is close to what I was looking for.
I'm looking forward to introduce and educate my friends in Java technology - especially servlets and JSP in order to show and prove them that this is better solution than C#.
I'm especially interested in ypur guidelines and tips when implementing MVC.

Enjoy your "stay" at the ranch.


Thanks.
I think the majority of questions I've been asked this week at the Ranch have been regarding MVC and moving from a model 1 architecture to a model 2 architecture. I'm glad to see that so many people are interested in that aspect of my writings.
Rather than restate everything again, I'd like to point you to the past 2 days worth of posts in this forum. I've stated my opinions and strategies regarding MVC in several posts. If there's anything you think I've missed, please post again.
Thanks!
Andrew
Andrew Patzer
Author
Ranch Hand

Joined: Jul 11, 2002
Posts: 30
Originally posted by Peter W Smith:
Andrew,
My friend bought your book and I read the first few chapters. I was glad to know I "invented" almost the same techniques for page navigation, error checking, etc. After finishing those chapters, I'm assured that my approaches were industry-strengthy.
However, I'd like to know more about how other people do logging and monitoring with web apps. specifically (but not completely), logging should happen at which points with what data, level? how to combine logging with sending error page back to user? how should logging of error tigger notification to administrators? etc.
I feel my approaches to the above is good, but need to confirm.
BTW, I want to have my own copy of your book, and for FREE
thanks


I'm glad you've enjoyed my book so far and have been able to validate what you're currently doing. As for logging, I strongly suggest that you use a package like Log4J from the Apache-Jakarta project. In fact, I do cover log4j in my book, which I believe I forgot to mention in my previous posts. Log4J allows you to declaratively set the logging level and loggin output. This makes it possible to categorize the information that you are logging and then manage it outside of the web application through property files.
As for monitoring of web applications, I have not done anything extensive in that area other than using management tools to monitor application clusters (F5 for instance). If you wish to add more detailed monitoring, you want to look into the Java Management Extensions (JMX) package and see what it has to offer.
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: This weeks giveaway : "JSP Examples and Best Practices".