Web tier: servlets, JSP, Web frameworks: Includes-Functions in Struts
- Posted by: Fernando del Rio
- Posted on: July 26 2005 05:28 EDT
Does struts have a tag to include (or call functions)???
I have the same code in 4 jsps and want to put it on 1 function but looking in the struts documentation i think there is no support to include funtions.
What do you mean by include-functions? Certainly you can use JSP includes with Struts or look at Tiles as a more capable version of this.
If you mean can you share scriptlets then you cna use the JSP include mechanism for that although if you are going to the bother of using a proper controller framework then you shouldn't really have much Java code in the pages in any case
I agree that you shouldn't be using that much Java code in the JSP pages, but if you find that you must, this is what I would suggest doing:
* Create a Java class with the code you need. It should have a no-argument constructor.
* Use the jsp:useBean tag to expose the class to your JSP as a scripting variable.
It is probably not a good idea to go too crazy using this technique, but you should find some way to avoid that cut-and-paste antipattern action you've got going on right now.
For the record, I believe that this is approach is essentially the View Helper pattern.
Thanks a lot!!
At last i rewrote all the page and now is more like a jsp...