File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes RequestDispatcher  forward method not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher  forward method not working " Watch "RequestDispatcher  forward method not working " New topic
Author

RequestDispatcher forward method not working

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi , i have written a simple servlet for forwarding to a page (www.google.com ) , but its not working , can anybody please tell whats the problem is :



On the execution of above the browser displays :

java.lang.IllegalArgumentException: Path https://www.google.co.in does not start with a "/" character


After appending with /



The browser shows a 404 error .

please tell whats the problem is .


Save India From Corruption - Anna Hazare.
Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154
Please read the API documentation which says that....


public RequestDispatcher getRequestDispatcher(java.lang.String path)


The pathname must begin with a "/" and is interpreted as relative to the current context root.

Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.

I hope it helps.


SCJP2, SCWCD
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks Rakesh , anyways my question remains the same.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Ravi,

RequestDispatcher cannot be used to redirect to external web sites. If you need to redirect to an external web site like http://www.google.com you have to use response.sendRedirect method instead.


Cheers,

Devaka.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you very much Devaka
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher forward method not working