aspose file tools*
The moose likes Servlets and the fly likes Request Dispatcher access file in another drive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatcher access file in another drive" Watch "Request Dispatcher access file in another drive" New topic
Author

Request Dispatcher access file in another drive

shail shailesh
Greenhorn

Joined: Oct 27, 2006
Posts: 3
Hi,

We have a website that was supposed to open-up a text file when a link is selected.

It had been implemented using
res.getRequestDispatcher("/<folder>/a.txt");
RequestDispatcher.forward(res,resp);

But now we are running short of space in server machine and hence need to move text files to a new location (on a separate system with a different ip).

The requestDispatcher doesn't work.
e.g requestDispatcher = res.getRequestDispatcher("<ip>/<folder>/a.txt");


Questions :
-------------
1. Is there an alternateway , perhaps URL or URI method?
<i am new to servlets, it is just a guess>

2. Should Some setting be done for accessing such files?


I use Websphere and Windows OS.

Thanks and Regards,
Shailesh
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

If your files are static and it isn't protected content, so there is no reason to use servlet for getting them. Your web server will do this job nicely and faster. Check you web server manual how to define aliases. You can also use SUBST Windows command to map another drive to a directory served under your servlet container, however this way smells as a hack.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Well, if you still insist on using RequestDispatcher to load the file up, you can try the following approach.

Deploy another web application to the same Web Container (In this case, to the same WebSphere instance). This web application will contain all the content files that you wanna load. And you can deploy it to another drive.

Then in your original web application, use ServletContext.getContext to get the ServletContext of the new application and subsequently use that to get the RequestDispatcher that load the text file you desired.

It's a way I thought off. Cheers.
[ October 28, 2006: Message edited by: Eddy Lee Sin Ti ]

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
shail shailesh
Greenhorn

Joined: Oct 27, 2006
Posts: 3
Hi,

Thanks for the replies!!

These are my concerns:
1. Minimal code change. (system is in production)
2. To know how existing systems are handling issues similar to mine.
3. Security issues .(system mainted by separate team)

The reason for RequestDispatcher was to avoid code change,
But after some persuation we can now do away with it.

I can't use the shared drive into container concept for security reasons.

The second system is a system in network with HDD space,
It has no server deployed on it. We can deploy nothing on it.

I looked around in the forum and found a "file upload thread".
So, i can use FileInputStream, But now i need to do it over network.

Question:
--------------
1. Is opening a socet the only way to read file over network?
e.g The file is at host ort/drive/filename.txt

2. One of the replies has "Check you web server manual how to define aliases" - What alias can be set in the server? is it for URL?



Thanks and Regards,
Shailesh
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Hi,

If URL is the only way allowed to access the resources, you can use the java.net.URL, then use the openConnection() method to create an URLConnection instance and subsequently retrieve the InputStream. Just need to make sure the security is properly configured.


Hope this helps. Cheers.
shail shailesh
Greenhorn

Joined: Oct 27, 2006
Posts: 3
Hi,

Thanks a lot for the answering the queries.!!

With everything pretty much clear only a clean implementation remains.



But if i may ask another question :

1. What would be the best way to solve such issues of space?
(no restrictions,
But i think the new HDD has to be in common place for clustered access)
2. Has anybody got a different idea.?


But I must metion again ,
The questions are purely for theoretical purposes.

Thanks once again...!!!

Thanks and Regards,
Shailesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Request Dispatcher access file in another drive