• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reusability in JSP  RSS feed

 
Sandep Chaturvedi
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Nehal Dave
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andrew Patzer
Author
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sandep Chaturvedi
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!