You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Samson, Lyndon [IT]" <ly...@ssmb.com> on 2001/06/06 13:27:51 UTC
forward() question
I have some code that looks something like this;
RequestDispatcher rd =
_req.getRequestDispatcher("/invalid.jsp");
try {
rd.forward(_req, _resp);
} catch ( ServletException e ) {
} catch ( java.io.IOException e ) {
}
The question is does control ever continue after the forward() method call?
It would seem sensible that it didn't
if you viewed forward as, I no longer wan't this page, but another one
instead.
My problem is that the above code is in a bean, which does an isValid user
check and forwards to a page if they are not. After the bean access I have
regular pages which are only mean to be displayed if the user is valid.
Like this;
<jsp:useBean id="userChk" class="package.UserValid"/>
<jsp:setProperty name="userChk" property="UserName" value="auser"/>
<jsp:setProperty name="userChk" property="UserPass" value="apass"/>
<% userChk.setPageInfo(request, response); %>
<jsp:getProperty name="userChk" property="IsValid"/>
<body bgcolor="#7080D0" link="#00FF00" alink="#000000" vlink="#00FFFF">
<font size="+1" color="#D0F0F0">
<p>
Show this if user is valid
</p>
</body>
What actually happens is the invalid page is shown, with the additional
"Show if user is valid" html appended to the end.
What can I do? I'd really like the forward to actually forward, not act like
include.
Re: forward() question
Posted by Wyn Easton <wy...@yahoo.com>.
Yes, you do return from the rd.forward() method call.
I always put a "return;" after such a call in my
servlets. Since your forward is done in the bean
try something like this:
<% userChk.setPageInfo(request, response);
if(!userChk.IsValid())
return;
%>
If you are interested, you can look at the Java code
that is generated by your JSPs in Tomcat's "work"
directory. That might give you a better idea of how
the generated servlet looks.
--- "Samson, Lyndon [IT]" <ly...@ssmb.com>
wrote:
> I have some code that looks something like this;
>
>
> RequestDispatcher rd =
> _req.getRequestDispatcher("/invalid.jsp");
> try {
> rd.forward(_req, _resp);
>
> } catch ( ServletException e ) {
> } catch ( java.io.IOException e ) {
> }
>
> The question is does control ever continue after the
> forward() method call?
> It would seem sensible that it didn't
> if you viewed forward as, I no longer wan't this
> page, but another one
> instead.
>
> My problem is that the above code is in a bean,
> which does an isValid user
> check and forwards to a page if they are not. After
> the bean access I have
> regular pages which are only mean to be displayed if
> the user is valid.
>
> Like this;
>
> <jsp:useBean id="userChk"
> class="package.UserValid"/>
> <jsp:setProperty name="userChk" property="UserName"
> value="auser"/>
> <jsp:setProperty name="userChk" property="UserPass"
> value="apass"/>
> <% userChk.setPageInfo(request, response); %>
> <jsp:getProperty name="userChk" property="IsValid"/>
>
> <body bgcolor="#7080D0" link="#00FF00"
> alink="#000000" vlink="#00FFFF">
> <font size="+1" color="#D0F0F0">
> <p>
> Show this if user is valid
> </p>
> </body>
>
> What actually happens is the invalid page is shown,
> with the additional
> "Show if user is valid" html appended to the end.
>
> What can I do? I'd really like the forward to
> actually forward, not act like
> include.
>
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/