Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2005, 02:14 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old June 28th, 2005, 04:38 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
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;
}

Reply With Quote
  #3 (permalink)  
Old June 28th, 2005, 06:39 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,
Having a return there does work.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:02 PM.


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