Reputation: 17174
What is the best way to implement the Composite View Pattern for a Java website?
My idea was to take one jsp and include multiple pages like:
<h1>Layout Start</h1>
<%
Values values = DataHandler.getValues(request);
LayoutHelper layout = values.getLayout();
out.println("Layout.getContent(): " + layout.getContent());
%>
<jsp:include page="<%= layout.getContent() %>" flush="false" />
<h1>Layout End</h1>
But then all my small jsp files in the WEB-INF directory are still available to the user. How can I deny access to all .jsp files except for the one template.
After that I need a filter or Servlet to insert the paths in the Values object.
Update
I don't mean that the WEB-INF is accessible from the file system (Or Webserver) but from the web app through the controller with my current layout layout.getcontent()
maps to an URL parameter/user input.
What are the common used frameworks to handle the Composite View Pattern??
Upvotes: 3
Views: 2528
Reputation: 7243
Pro Java EE and Spring Patterns mentions two popular framework that supports the Composite View pattern:
Personally I used Tiles and It worked like a charm integrated with Struts and Spring. SiteMesh also relies on the Decorator Pattern. In Tiles Web Site there's a nice comparison between the benefits of both patterns.
Upvotes: 3
Reputation: 9914
Apache Tiles is working on this concept.
http://tiles.apache.org/framework/tutorial/pattern.html
It is worth looking into this.
Upvotes: 2
Reputation: 51965
Any file that's in WEB-INF
is not directly accessible by the user. I typically put all my JSPs in WEB-INF/jsp
, and then only the controller servlet (or other JSP pages) can access them.
Upvotes: 4