Looking at the java file generated from one of my jsp's that contains a
<jsp:forward> directive reveals the following code :
public void _jspService(HttpServletRequest request, HttpServletResponse
response)
{
... stuff omitted ...
PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this,
request, response, null, true, 5120, true);
out = pageContext.getOut();
... stuff omitted ...
// start of <jsp:forward> logic
if( <some expression deciding whether you want to forward> )
{
out.clear(); // clear current output buffer
pageContext.forward("main.jsp"); // forward to specified page
return; // after main.jsp executes we don't want to continue processing the
rest of the current page, so return
}
If you wanted to pass the pagecontext object to your bean it could implement the
forwarding internally. The problem is that when your bean's method returned (after
internally indirectly executing the other jsp's service method) the current page would
need to know that it should return instead of continuing to output/process the rest of
the (now incorrect) page. Possibly a better approach would be to have your bean
return a value indicating that a forwarding should occur. For example (please ignore
any improper syntax):
<jsp:usebean id="loginBean" ....>
blah blah
<%
if(loginBean.authFailed())
{%>
<jsp:forward page="failed.jsp">
<%}%>
blah blah rest of page
If you want the bean to have more control over what page is forwarded to, you could
try something more like :
<%
String forwardTo = loginBean.authenticate();
%>
<jsp:forward page= <%=forwardTo%> >
Hope that helps,
Brien Voorhees
----- Original Message -----
From: Thomas Cox <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 05, 1999 11:27 AM
Subject: how redirect from bean instead of jsp file
> Thanks Eric:
>
> Now a related question: how can I give redirect command from within the bean,
> rather than from with
in the JSP page. I know I can use the <jsp:forward> in the
> JSP page, but I want to do this in a class called using the useBean tag.
This
> question is analagous to the one below where I wanted to use the bean to
output
> HTML directly.
>
> Thanks for any help.
>
> Tom Cox
> _________________________________________________________
>
> Thomas Cox
> Solution Center of the Americas Phone: +1.612.397.4226
> 400 One Financial Plaza Fax: +1.612.692.4226
> 120 South Sixth Street Alt Fax: +1.612.397.4370
> Minneapolis, MN 55402 e-mail: [EMAIL PROTECTED]
> _________________________________________________________
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> Sent: Tuesday, September 28, 1999 8:16 AM
> To: Thomas Cox
> Subject: Re: Output from Bean to JSP file
>
>
> All you have to do is pass the out object or the response object to the
bean
> and do something like this in the bean method:
>
> out.println("<BR>Hi");
>
> The JSP scriplet coud be like this:
>
> <%
> MyBeanRef.setPrintWriter(out);
> %>
>
> Eric Dunstan
> VEC 1999
>
> >From: Thomas Cox <[EMAIL PROTECTED]>
> >Reply-To: Thomas Cox <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Output from Bean to JSP file
> >Date: Fri, 24 Sep 1999 08:06:40 -0500
> >
> >I'd like to called a bean method from a scriptlet in my jsp that will
> >output
> >html into the page.
> >
> >This method will not be related to any existing input field on the jsp by
> >name.
> >I don't want to use an include file because I want this code centralized
in
> >the
> >bean.
> >
> >Is there any way to do this, or am I ONLY allowed to put methods in the
> >bean
> >that relate to existing input fields on the jsp page?
> >
> >Thank you.
>
>
===========================================================================
> 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
>
===========================================================================
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