• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Redirect to a file on server

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vani Bandargal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
It's exactly the same and completely different as this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic