There is one subject that really intrigues me: All the reusability in JSP application revolves around use of a javabean or custom tags. JSP has a seemingly powerful feature of page directive "extends" using which one should be able to come with a JSP hierarchy and introduce reuability at the core - similar to java class hierarchy. Why is there never any discussion around that. Is that not useful or difficult to comprehend for JSP developers? Even on java site, that feature has never got much writting! Andrew or other : any expert opinions??
Sandep Till i know one should not extend Jsp pages for following reasons : As we all know Jsp pages r compiled in servlet classes by servlet containers. They compile the Jsp pages to their custom classes which implement HttpServlet. They use this feature to increase the performance.(Al least thats what i read somewhere.. ) So if u extend your JSP to some other custom classes it may create probs... or decrease the performance.. Personally i am confused abt this thing.. so just wanted to make u confused too... Cheers Nehal
I personally prefer to use custom tags to store common functionality and reuse it across many different pages. There are 2 reasons for this. First, using custom tags is much simpler for a basic web developer (not a Java programmer) who needs to access the functionality but may not know what methods exist in the superclass. Usually, custom tag libraries are documented and are simple to use (well, maybe not always documented, but their structure is similiar to HTML and certainly more intuitive for a web developer to figure out). Second, custom tags make efficient use of system resources thereby enhancing performance. Servlet containers create a pool of instances of a custom tag and manage the use of them. I've added methods to a JSP page, then subclassed it to reuse methods across multiple pages before. I once did this to add some standard form validation methods that I could call within each page to validate fields and display errors back to the user for individual fields (ie. highlight the fields in error). It works okay, and I don't think you're violating any major design principles, but using custom tags is a much better option for the reasons stated above. 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>
posted 16 years ago
Andrew, I think Custom Tags must be treated as "flyweight" components and definitely has its role in JSP development. Similar to Javabeans which stores the "model". But taking away the extensibility from JSP introduces redundancy in my opinion. Just to make things easier for JSP developers, why take away this useful feature. I think, we got so used to write JSP's the way we do, we totally forgot about it.
Originally posted by Sandep Chaturvedi: Andrew, I think Custom Tags must be treated as "flyweight" components and definitely has its role in JSP development. Similar to Javabeans which stores the "model". But taking away the extensibility from JSP introduces redundancy in my opinion. Just to make things easier for JSP developers, why take away this useful feature. I think, we got so used to write JSP's the way we do, we totally forgot about it.
JSPs are not intended to be written by developers who understand class extension. They are intended to be written by front-end designers.
James Carman, President<br />Carman Consulting, Inc.