aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Path ... doubts! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Path ... doubts!" Watch "Path ... doubts!" New topic
Author

Path ... doubts!

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
Hi
Can someone clear my doubts about the url path, when it is relative and when absolute.
Here is wht i gathered:
1)getRequestDispatcher - With ServletRequest relative path within the current context.
With ServletContext path only absolute.
2)getContext - absolute path
3)sendRedirect - absolute path
Is there any easy way to remember about where its relative and where absolute...i'm confused.
faiza
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I'd like to make a guess, but I am probably wrong.
This of what you are getting back. For instance in sendRedirect, you might want to send it to another Application, that isn't in the current Apps main directory.
I mean if the .war file is in c:\server\webapps\myApp\myApp.war
and you want to redirect to an app that is at
c:\server\webapps\MyOtherApp\otherApp.war
you wouldn't be able to do that because with relative paths because it would start at c:\server\webapps\myApp\
1) A RequestDispatcher that comes from ServletRequest is within the App, whereas the ServletContext is with the server, therefore you can get to other Apps in the server with the ServletContext.
That's my thinking, so from that I made it all up, but it might be right. It makes sense that way to me )
Good Luck
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
1)getRequestDispatcher - With ServletRequest relative path within the current context.
With ServletContext path only absolute.

ummm..nope!!!
RequestDispatcher from ServletRequest you can use relative paths (paths not starting with a "/") that are relative to the current request. You can also use absolute paths (paths starting with a "/") and these will be treated relative to the ServletContext or web-app root.
RequestDispatcher from the ServletContext must use a path that is relative ONLY to the ServletContext and ust start with a "/".
Go thru your other post I have analyzed the example for you (with the help of Axel).
I will talk abt the other two methods as I read them maybe tomorrow.
regds.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

1) A RequestDispatcher that comes from ServletRequest is within the App, whereas the ServletContext is with the server, therefore you can get to other Apps in the server with the ServletContext.

ummm...Mark: I have to disagree with you on this.
Acc to SRV.8.1 of the 2.3 Spec...
The path specified to the getRequestDispatcher(...) method of the ServletContext should be within the scope of the ServletContext.
Doesn't that mean that we are restricted to the web-app in question?
Atleast thats what I think.
Anyother views please....
Thanks.
- satya
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Originally posted by Madhav Lakkapragada:
RequestDispatcher from ServletRequest you can use relative paths (paths not starting with a "/") that are relative to the current request. You can also use absolute paths (paths starting with a "/") and these will be treated relative to the ServletContext or web-app root.
RequestDispatcher from the ServletContext must use a path that is relative ONLY to the ServletContext and ust start with a "/".
- satya[/QB]

Satya,
without wanting to be annoying. But for my understanding an absolute pass allways starts with http://.
I would say that we can use absolute paths (1) THIS DOES NOT WORK!!! and two syntaxes of relative paths (2) and (3).
THE FOLLOWING DOES NOT WORK!!!
(1) ServletRequest.getRequestDispatcher("http://127.0.0.1:8080/test/servlet/ForwardedServlet");
THIS DOES WORK!!!
(2) ServletRequest.getRequestDispatcher("/servlet/ForwardedServlet");
this is relative to the context of current webapp.
THIS DOES WORK!!!
(3) ServletRequest.getRequestDispatcher("ForwardeedServlet");
this is relative to the forwarding Servlet.
regards
Axel
[ February 03, 2002: Message edited by: Axel Janssen ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
When it comes to technology, I am a shameless guy. If you think I am wrong I may be wrong. I pprefer to beleive the facts. Terminology is always confusing to me.
I haven't tried the absolute form
(1) ServletRequest.getRequestDispatcher("http://127.0.0.1:8080/test/servlet/ForwardedServlet");
I agree to your definitions of absolute and relative. I myself, had a hard time accepting my definitions. But I think we are clear of the point re "how to use these paths?".
I was trying to re-state what is stated in the Spec in my own way.
regds.
- satya
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
used wrong english word.
Did not want to say embarass. Wanted to say sth like don't want to be annoying.
Will check dictionary first next time.
Axel
[ February 03, 2002: Message edited by: Axel Janssen ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

used wrong english word.
Did not want to say embarass

Take it easy.....I am not offended...
Your english is fine. You don't have to
use a dictionary...we are techies not
lawyers or literature gurus anyways....
- satya
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

(1) ServletRequest.getRequestDispatcher("http://127.0.0.1:8080/test/servlet/ForwardedServlet");

This doesn't work for me, Tomcat 4.0.1 on NT.
Is this supposed to work ?
From the example in the other post, I see:
its not good to forget b-days
in the browser and the forward fails.
regds.
- satya
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
No this does NOT work here neither.
So we have only the two relative paths.
Will correct my above post.
Axel
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

2)getContext - absolute path
3)sendRedirect - absolute path

Discussed in seperate threads.
Thanks.
- satya
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

No this does NOT work here neither.

Thanks.

So we have only the two relative paths.

Yup, lets settle for this.
Hey, Thanks for all your help. Things are much clear for me after all this exercises.
Glad faiza asked these qstns.
- satya
faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
Hey Satya and Axel.....that was a great discussion and sorry i wasnt a part of it...due to my domestic (unrecognized ) obligations
Letme digest all the important points and i'll surely come back....mmm...maybe with more doubts
thanx
faiza
Sharon
Greenhorn

Joined: Jun 24, 2002
Posts: 2
I have also found that this does not work
ServletRequest.getRequestDispatcher( http://127.0.0.1:8080/test/servlet/ForwardedServlet);
Do u know what is the method that I can use if I want to get the content by using absolute path?
Thanks.
Sharon
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5370
I think RequestDispatcher works for only one Servlet Context(web-app) so first of all you can not get RequestDispatcher for another web-app.
and as SUN guys for absolute path use "/".
I think sendRedirect() should solve this problem.
obviously you can not include resources from differnet web-app.
CMIW
HTH


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Sharon
Greenhorn

Joined: Jun 24, 2002
Posts: 2
Thanks Ravish.
But I really need to include resources from different web-app and do some processes. So it cannot be solved by using sendRedirect(). Anyway, thanks!
Sharon
k space
Ranch Hand

Joined: Jun 25, 2002
Posts: 104
Try obtain a foreign context first, e.g. Servlet.getContext("/test"), then invoke getRequestDispatcher() on that context.


SCEA | SCBCD | SCWCD | SCJP - The kSpace
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5370
but still it has to be on the same server ...
CMIW
TIA
Didi Dia
Greenhorn

Joined: Feb 13, 2003
Posts: 1
Originally posted by ks wong:
Try obtain a foreign context first, e.g. Servlet.getContext("/test"), then invoke getRequestDispatcher() on that context.

I take a look on the specification, there is no such a method : Servlet.getContext(contextName)in the Servlet. Can you tell me which version you are using. I want to be able to get a foreign context from another.
Sumit Amar
Ranch Hand

Joined: Jun 08, 2002
Posts: 180
Great discussion. I feel specification suggests to use "/" prefixed URIs for absolute paths. I haven't come accross any example where "http://" was prefixed.
Cheers


SCJP, SCWCD, OCA, OCP-DBA 9i, <a href="http://brainbench.com/transcript.jsp?pid=2232802" target="_blank" rel="nofollow">BCIP</a>, MCP, MCAD, MCSD.NET, MCDBA, MCTS (SQL 05), MCITP (DBD, DBA)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Path ... doubts!
 
Similar Threads
plz help me
Cannot find symbol Error
Absolute path , Relative Path
pom.xml ERROR
Not able to find a File in servlet