• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RequestDispatcher.forward problem

 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that forwards to a page with frames. I am forwarding to a relative url in a sub-folder of the web app. It is able to find the relative url, but it does not find the frames. I get a 404 error in each frame telling me that it did not look in the same folder that the main page is in. Does anyone have any ideas on how to resolve this?
 
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Matthew Phillips:
I have an application that forwards to a page with frames. I am forwarding to a relative url in a sub-folder of the web app. It is able to find the relative url, but it does not find the frames. I get a 404 error in each frame telling me that it did not look in the same folder that the main page is in. Does anyone have any ideas on how to resolve this?


The most "modular" way to do it is by mapping the servlet to a URL in the same subdirectory of your frameset. So if the frameset is in some-sub-directory, add a mapping to web.xml:
<servlet>
<servlet-name>test-me</servlet-name>
<servlet-class>com.testme</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test-me</servlet-name>
<url-pattern>/some-sub-directory/testme</url-pattern>
</servlet-mapping>
Then when you call the servlet with http-app-path/some-sub-directory/testme, the relative paths will work.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a servlet have multiple url mappings? The servlet could return 1 of three screens based on input data. The framesets are in 3 seperate folders. I also already have a url map so that I do not have to call the servlet by /servlet/servlet-name.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this forward (I mean since it forward), the url for your frames should be relative to your original location.
If user tryed to access folder1\file1.html,
but you forward him to ..\folder2\file2.html, and file2.html contains some frames, request for this frames will be sent by a browser, and for browser you are still at folder1\file1.html. So if you frame url was frame2.html and frame2.html locate at folder2, frame url should be ..\folrder2\frame2.html
 
John Fontana
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Matthew Phillips:
Can a servlet have multiple url mappings? The servlet could return 1 of three screens based on input data. The framesets are in 3 seperate folders. I also already have a url map so that I do not have to call the servlet by /servlet/servlet-name.


Yes, you can have multiple URL mappings. According to "Core Servlets and Java Server Pages", this is the preferred approach.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yuriy Fuksenko:
For this forward (I mean since it forward), the url for your frames should be relative to your original location.
If user tryed to access folder1\file1.html,
but you forward him to ..\folder2\file2.html, and file2.html contains some frames, request for this frames will be sent by a browser, and for browser you are still at folder1\file1.html. So if you frame url was frame2.html and frame2.html locate at folder2, frame url should be ..\folrder2\frame2.html


I tried that and it didn't seem to work.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am being really dense today. Let me post some code and maybe that will help.
This is the page my web app is forwarding to:


My directory struction is as follows:
alumni -- web app directory
administratorPages -- contains the above and all frames
The error I am getting in each frame is "/alumni/"frameName".jsp does not exist.
My web.xml file looks like this:



I have also tried the following mappings:


The url that I am passing to the forward method of RequestDispatcher is "/administratorPages/framesMain.jsp". framesMain.jsp is the name of the page above. What am I missing on this?
[ May 15, 2002: Message edited by: Matthew Phillips ]
 
John Fontana
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use the second mapping that uses the administratorpages uri, then you do not want to specify that directory in your RequestDispatcher. It would look for a subdirectory in administratorpages called administratorpages.
Just use /framesmain.jsp in your RequestDispatcher, and use the second url-mapping you listed.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Fontana:
If you use the second mapping that uses the administratorpages uri, then you do not want to specify that directory in your RequestDispatcher. It would look for a subdirectory in administratorpages called administratorpages.
Just use /framesmain.jsp in your RequestDispatcher, and use the second url-mapping you listed.


That one yeilded a 404 error "/alumni/framesMain.jsp was not found on this server."
 
John Fontana
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I see that it's an MVC-pattern controller servlet (correct me if I'm wrong)...A little tricky to troubleshoot without seeing the Servlet code (for example, is there a parameter being passed to the servlet and an if-then block to redirect?).
As an aside, if you don't have to pass request/response content to each JSP, then you could get away with using sendRedirect instead of RequestDispatcher....this will actually change the URL in the browser and you won't need to worry about mappings.
Anyway, feel free to send me the code if you like...I'm studying for SCWCD anyway and could use the practice...Also preferential treatment for fellow Kiss fans/musicians
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your wish is my command:
The controller servlet is as follows:

It is pretty much the same as the example in Chapter 6 of Professional JSP Second Edition.
The action that handles login is as follows:

The forward method is in ActionBase and is as follows:

My understanding of url mapping certainly isn't the greatest, but it seems like this should work. The frame set opens ok by going directly to the url. When the servlet forwards to it, it just doesn't seem to pick up the other frames. Could this be a jsp issue?
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sendRedirect works, so I will stick with that. I am still curious as to why forward doesn't. Thanks for the assistance so far guys.
 
John Fontana
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to write a little mini-app that works...here's a very stripped down version of it:
The "controller":

I put the frameset and its files in a subdirectory called administrator pages. Here's the mapping:

I called it using url: http(app-path)/administratorpages/test-me and it took me right to the frameset with no 404 errors.
Hope this helps!
[ May 15, 2002: Message edited by: John Fontana ]
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Fontana:
I called it using url: http(app-path)/administratorpages/test-me and it took me right to the frameset with no 404 errors.
Hope this helps!
[ May 15, 2002: Message edited by: John Fontana ]


I may not have been clear at the beginning. Calling the path that way has always worked. When the LoginAction forwards to the relative url is when I have the problem.
reply
    Bookmark Topic Watch Topic
  • New Topic