File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Redirect to a file on server 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 » Frameworks » Struts
Bookmark "Redirect to a file on server" Watch "Redirect to a file on server" New topic
Author

Redirect to a file on server

Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
In our struts application, we are redirecting to an HTML file on the server on some button click. We have following requirement for the same.
1.Don't show the name of the file that's up on the server
2.The path where the file is loacted.

We want to know if there is a way to achieve both 1 and 2 OR atleast any one of this.

thank you for any suggestions.
[ August 07, 2008: Message edited by: Vani D Bandargal ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you define an action that forwards to the html file. Example:

In this case, the URL used to get to this page is www.mycompany.com/myapp/myHtmlPage.do and the actual path to the file and its name are completely hidden.


Merrill
Consultant, Sima Solutions
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
Thank you very much Merill.

I apologize for not fully explaining the requirement.

We deploy this application on different servers like demo, test server and the actual prod server. Depending on the server, the path gets changed. how do we handle this?
[ August 07, 2008: Message edited by: Vani D Bandargal ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
We deploy this application on different servers like demo, test server and the actual prod server. Depending on the server, the path gets changed. how do we handle this?


We handle this by changing the data in the configuration file prior to deployment.
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
Thank you James.
Can you please share how to do the same.

Also, is there a way to handle this dynamically?
Please note that the file that we are pointing to on the server is not same.(file names could be different)

It is a file that user uploaded to the server. We will let user to review the file once he uploaded. We will let user to review only once as soon as he uploaded. There is no second chance once he logs off

[ August 07, 2008: Message edited by: Vani D Bandargal ]
[ August 07, 2008: Message edited by: Vani D Bandargal ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thank you James.
Can you please share how to do the same.


Open configuration file in a text editor, go to text you want to change and delete it, type in new text and save file.

Also, is there a way to handle this dynamically?
Please note that the file that we are pointing to on the server is not same.(file names could be different)


There is a way to handle your requirement programatically. You need to keep track of the directory name and the file name of the file being uploaded. The directory name is the tricky part. You will need to manually enter this when deploying the application as a parameter.
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
I would like to add more information to help us find the solution.
We have means to check which server the app is on.

We have a file up on each server (ServerType.txt) which will contain DEV or TEST or PROD values depending on where that file itself is.

We are already doing something like this to get the host name in other situation.

protected String getHostURL(HttpServletRequest request)
{
HttpSession session = request.getSession();
String hostURL="";
String deploymentType = HinProperties.getHinProperties().getStage();

if (deploymentType.equals("") || deploymentType.equals("DEV"))
{
hostURL="https://devserver.mycomany.state.xx.us/";
}


if (deploymentType.equals("TEST"))
{
hostURL="https://testserver.mycomany.state.xx.us/";
}


if (deploymentType.equals("PROD"))
{
hostURL="https://prodserver.mycomany.state.xx.us/";
}
session.setAttribute("hostURL",hostURL);
return hostURL;
}
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
Originally posted by James Clark:


There is a way to handle your requirement programatically. You need to keep track of the directory name and the file name of the file being uploaded. The directory name is the tricky part. You will need to manually enter this when deploying the application as a parameter.


Thank you very much James for taking time to answer my question.

We just now tried to create ActionForward object in our action class like below using the getHostURL method that I explained in my earlier post.

It is still showing the file name along with the directory up on the server where we have stored that file.

Please see the code below.

public class ReportTesterAction extends Action {
.
.
.
ActionForward forward = new ActionForward(getHostURL(request) + report_output_loc + report_output_file, true);

return (forward);
}
[ August 07, 2008: Message edited by: Vani D Bandargal ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thank you.

Creating an ActionFoward with the configuration file (example below) will only work for a static filename that is hard-coded in the configuration file. Since in your case, the file-names will be different for each user, this will not work. And as you state, creating the ActionForward in the Action class will not shield the file-name or directory name. Another solution must be found.

<action path="/myHtmlPage" forward="/somepage.html" ></action>


In regards to the Action that is used to view the uploaded file, you can to code the Action to send the file back in the HttpResponse. This will protect the physical location of the file. You will need to read the bytes of the file and prepare the HttpResponse in the Action .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirect to a file on server