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 June 28th, 2005, 02:14 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default question about RequestDispatcher forward

Hi,

I've been using RequestDispatcher.forward in some of my jsp codes.
I always thought that when this is called, the page gets forwarded and the rest of the file will not be excuted any more. But recently I just realised that is not the case.

I have some simple code that does this:

<%

int i = 0;
RequestDispatcher dispatcher = null;
String url = "/somepage.jsp";

if (i == 0) {
  dispatcher = getServletContext().getRequestDispatcher(response. encodeURL(url));
  dispatcher.forward(request, response);
}

System.out.println("PRINT AFTER FORWARD");

%>

When running this page, it does the forwarding and then itcontinues to excute the rest of the page.

Does anyone have a clear explanation for this?

Thanks
 
Old June 28th, 2005, 04:38 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try:

if (i == 0) {
  dispatcher = getServletContext().getRequestDispatcher(response. encodeURL(url));
  dispatcher.forward(request, response);
  return;
}

It worked for me, but my code was different:

if (!sUser.validateForPage(form)==true)
{
    response.sendRedirect("login.jsp?loginFailed=false ");
    return;
}

 
Old June 28th, 2005, 06:39 PM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,
Having a return there does work.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward after Login ~Bean~ ASP.NET 1.0 and 1.1 Basics 1 July 14th, 2005 05:14 PM
Using RequestDispatcher in JSP using Context Obj siddsonline J2EE 0 April 12th, 2005 07:20 AM
RequestDispatcher problem sherbir Servlets 0 July 7th, 2004 11:51 PM
Forward booking rahilahmed Pro VB Databases 1 June 16th, 2004 06:02 PM
Forward Booking rahilahmed Excel VBA 0 May 24th, 2004 09:25 AM





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