Hello!

I have a bunch of pages I want to include in a framework. The code for the
framework is in the template.jsp file shown below. Subpages can set
miscellaneus properties for the framework via request.setAttribute(), for
example a title property for the <TITLE> tag.

I wonder, is this a bad design? Are there any better ones?

-------------------

template.jsp

<%
 String title = (String)request.getAttribute("title");
 if (title == null) {
  title = "Default Title";
 }
%>

<HTML>
<HEAD>
<TITLE><%= title %></TITLE>
</HEAD>
<BODY>

start of template
<BR>

<%
 // INSERT HERE
 String include = (String)request.getAttribute("include");
 if (include != null) {
  RequestDispatcher dispatcher = application.getRequestDispatcher(include);
  if (dispatcher != null) {
   out.flush();
   dispatcher.include(request, response);
  }
 }
%>

<BR>
end of template

</BODY>
</HTML>

--------------------------

subpage.jsp

<%
 String uri = request.getRequestURI();
 String include = (String)request.getAttribute("include");
 if (include == null) {
  request.setAttribute("title", "Subpage title");
  request.setAttribute("include", uri);
  RequestDispatcher dispatcher =
application.getRequestDispatcher("/template.jsp");
  if (dispatcher != null) {
   dispatcher.forward(request, response);
  }
  return;
 }
%>

<BR>This is a subpage...<BR>

--------------------------

(Since this is a lot of code (subpage.jsp) to include in each page, I should
put it in a bean method.)

Any help is VERY, VERY much appreciated!

-Haakon Emblemsvaag

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to