I'm trying to find a simple solutions to generate markup in a JSP page that needs to be reused within that page.
The templated markup would have scriptlet calls within it, with some localized Java declarations.
For example:
<markup>
<% MyObject localObject = controller.getMyObject(); %>
<name><%= localObject.getName() %></name>
<value><%= localObject.getValue() %></value>
</markup>
I want to be able to reuse the construct above multiple times in a JSP file wit开发者_JAVA技巧hout there being any multiple local variable conflicts.
Is there a best practice for doing this in JSP? Do tag files introduce their own level of scope in terms of local declarations as opposed to a simple include directive?
EDIT: I also need the local variable to be passed to the templated structure.
There are 2 options
- Dynamic includes (server side includes)
- Tag files
Static includes will not work in this scenario as there will be variable name conflicts.
Yes, tag files have their own scope.
精彩评论