Hi,
I thought i shall be smart, i developed my own:
IncludeServletResponse that implements HttpServletResponse)
That one routes everything to the base servlet response of the pagecontext
except the outputstream ones:
The getOutputStream() returns not the default one of the first Response
but my own implementation but now the bug of Tomcat??:
IncludeResponse iResponse = new
IncludeResponse((HttpServletResponse)pageContext.getResponse());
RequestDispatcher rd=
pageContext.getServletContext().getRequestDispatcher(_sPage);
rd.forward(pageContext.getRequest(), iResponse);
iResponse is my own implentation.
The RequestDispatcher interface wants only a ServletResponse (and a
ServletRequest)
It compiles fine so how is it possible that the RequestDispatcher throws a
ClassCastException inside itself?
What kind of ServletResponse does it wants?
Johan Compagner
> -Original Message-
> From: Johan Compagner [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 05, 2001 4:05 PM
> To: Struts-User
> Subject: Template layout file with an include (bean or jsp) to a jsp
> with a form.
>
>
> Hi,
>
> I will ask the basic question first so that you don't have to
> read the whole
> email:
>
> So is there no way to use the same request over 2 or more jsp
> files that are
> nested in
> each other?
>
> Now my test case:
>
> I have a template jsp file that has all the layout of my site.
> in the right left corner will al the dynamic data.
>
> like this:
>
> // tag libs includes
>
>
>
>
>
>
> cellspacing="0"
> bgcolor="#0066ff">
>
>
> // standard layout of my site
> // jadajadajadajada
>
> // The include logic.
>
>
> <%= subpage %>
>
>scope="request">
>
> <%= subpage %>
>
>
>
>
>
>
> This template file is always the ActionForward that i return as the next
> page to see
> after this action, something in the perform method of a Action:
>
> request.setAttribute(Constants.JSP_INCLUDE_KEY,
> mapping.findForward("pensioen3a").getPath());
> return mapping.findForward("template");
>
> The nicest thing about this is that if i want to change something
> of my site
> i only have to edit
> one file and every page/view is changed also like the logon page or the
> pages with the forms.
>
> But now my problem.
>
> An Action is mostly triggerd by the subpage (where the form is in).
> That Action is testing the input (some validation) if that goes wrong that
> a ACtionError is made and is attached to the request.
> But when i forward it (to the same page) i forward it to the
> template again
> and that
> template includes the page with the form.
> But the include generates another request for that subpage so my
> ActionErrors object
> and other objects that i stored in the request aren't there!!
>
> I also do this in te validate() of a Form:
>
> String fromPage = request.getParameter("frompage");
> mapping.setInput(mapping.findForward("template").getPath());
> request.setAttribute(Constants.JSP_INCLUDE_KEY,
> mapping.findForward(fromPage).getPath());
>
> So that when there are errors returned it knows that the input is the
> template and the
> include is the same page it come's from.
>
> But this also doesn't work.
> I can't be the only one with this problem.
> Are nobody else using subpages where the form/inputs are in an another one
> that is the standard layout page?
>
> I thought to be smart and made my own include tag:
>
> public int doStartTag() throws JspException
> {
> try
> {
> RequestDispatcher rd=
> pageContext.getServletContext().getRequestDispatcher(_sPage);
> rd.forward(pageContext.getRequest(),
> pageContext.getResponse());
> } catch(Exception e)
> {
> throw new JspException(e.getMessage());
> }
> return SKIP_BODY;
> }
>
> But the problem is then that the subpage (the _sPage string) is displayed
> first, above
> the main page instead of in the main page. Why is this? Because
> when i walk
> through the code
> then i see the main page that writes to the output and then the
> subpage and
> then the main
> page again. I think this has something to do with flushing ect.
> But if i flush first (right above the RequestDispatcher line i do this:
>
> pageContext.getOut().flush();
>
> Then i get the main page on top again but an error in the place where the
> subpage should be:
>
> Location: /postbank/template.jsp
> Internal Servlet Error:
>
> javax.servlet.ServletException: Cannot forward as
> OutputStream or Writer
> has already been obtained
>
> So is there no way to use the same request over 2 or more jsp
> files that are
> nested in
> each other?
>
> Johan
>
>
>
>
>
>
>
>