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.
|