Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2008, 03:05 AM
Registered User
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default master page in JSP

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
The Following User Says Thank You to tanzi For This Useful Post:
 
Old May 29th, 2008, 08:47 PM
Registered User
 
Join Date: Oct 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First - what have you done to help yourself?

 
Old June 5th, 2008, 06:40 AM
jomet
Guest
 
Posts: n/a
Default


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.
 
Old November 2nd, 2008, 07:22 PM
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
Default

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.


The Following 2 Users Say Thank You to foulton For This Useful Post:





Similar Threads
Thread Thread Starter Forum Replies Last Post
Master Page Method: Code-Behind for Content Page kwilliams ASP.NET 2.0 Professional 3 June 2nd, 2008 12:57 PM
Master Page and Content Page with Java script Harjinder ASP.NET 2.0 Professional 1 February 1st, 2008 10:31 AM
master page and content page interaction mrjoka ASP.NET 2.0 Basics 0 March 15th, 2007 10:45 AM
Access Master page control from Content page. angshujit ASP.NET 2.0 Basics 3 January 11th, 2007 06:20 AM
Bookmark this page link in Master page dschips ASP.NET 2.0 Basics 5 January 8th, 2007 11:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.