Subject: master page in JSP
Posted By: tanzi Post Date: 5/27/2008 3:05:02 AM
hi all,

i m new to JSP n want to include master page feature in my project.

plz help me in doing so.

regards

tanzi
Reply By: I5commuter Reply Date: 5/29/2008 8:47:47 PM
First - what have you done to help yourself?

Reply By: jomet Reply Date: 6/5/2008 6:40:09 AM

in my knowledge master page feature is in asp.net

use css templates instead


jomet.
````````````````````````````````````````````````````````````````````````
Once you start a working on something, dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.
Reply By: foulton Reply Date: 11/2/2008 6:22:19 PM
I got interested for the problem so I found out something for you.

First we have to create an embedded page, we can name it for example "TestForm".

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head/>
  <body>
      <%
           if (request.getParameter("fromMasterPage") == null)
           {
                %>
                  <jsp:forward page="masterpage.jsp">
                    <jsp:param name="embeddedPageName" value   
                     ="testform.jsp"/>
                     <jsp:param name="submitPageName"  value   
                     ="processdata.jsp"/>
                  </jsp:forward>
                <%
           }
      %>
      <input type="submit" value="go to processdata.jsp"
      name="submit"/>
  </body>
</html>

If the page even has not been included in the masterpage, we have to
forward to a masterpage witch will contain it (the forward will not change the context parameters e.g: request parameters or attributes, current path etc.)
After that we can dinamically include any other
page into the masterpage and we can also dinamically set the form's action parameter. See this in the first snippet in jsp:forward.

This is the master page:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head><title>Simple jsp page</title></head>
  <body>
      <%
        String embeddedPageName =
        request.getParameter("embeddedPageName");
        String submitPageName =
        request.getParameter("submitPageName");
      %>
      <form action="<%= submitPageName %>" method="POST">
      -- Header --
         <br/>       
         <jsp:include page="<%=embeddedPageName%>">
         <jsp:param name="fromMasterPage" value="true"/>
         </jsp:include>
         <br/>
      -- Footer --
      </form>
  </body>

"jsp:include" also preserves all request info.
"fromMasterPage" will be set to "true" to prevent another forward to masterpage. This is something like that asp does.
I think you could wrap the part between header and footer
into an ajax panel (AjaxTags). I hope it will work well in every cases.



Go to topic 74900

Return to index page 1