Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java http servlet response redirect not working for mapped drives

Posted on 2008-09-29
2
Medium Priority
?
1,205 Views
Last Modified: 2013-12-02
Hi
  I am using tomcat and would like to redirect my servlet to a particular file server location after some validations.My file server is say mapped at X:\test.I am trying to use response.sendRedirect("file:///X:\test").But that doesnt work.It doesnt throw any exceptions at the backend but gives a page not displayed error.Evne if I try a "file:\\c:\\" on my local box , I get this error.I initially thought it would have to do with permissions but since I cant even access my local box , I guess the problem is something else.Can you please help?
Thanks
0
Comment
Question by:res_this
2 Comments
 
LVL 1

Accepted Solution

by:
MrMarshall earned 1500 total points
ID: 22599757
A HTTP Redirect is a command that tells the browser that it is being redirected to a new URL this differs from a Forward which simply forwards the Browsers request to a new Url without informing the Browser.

However, since the browser is involved the location needs to be accessible by the Browser and relative to the server.

It sounds like you want to return the file to the Browser as a response to the request. You should look into writing the file to the output stream.
i.e. See Code Attached.

Hope this helps.



	
 
        FileInputStream in=new FileInputStream("X:\\Test");
    	byte[] buffer=new byte[1024];
    	int count=0;
    	OutputStream out=	response.getOutputStream();
    	while((count=in.read(buffer))!=-1){
    		out.write(buffer);
    	}
    	

Open in new window

0
 

Author Comment

by:res_this
ID: 22600043
Hi,
    Thanks , but I dont have to display the file contents.The idea is the viewer should be able to navigate
the X://test folder and be able to view its contents.
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
A solution for Fortify Path Manipulation.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question