0

This is my second shot at asking the question - I'll provide some more details this time to help get an informed answer.

What I'm trying to really do here is populate a drop-down menu with data that is dynamically generated from an executable that's supposed to run on a page load. The catch is, the executable must be in a directory local to the JSP on the server. My company has 3 or 4 clones of this website and I cannot place the executable in some absolute filepath - it must be relative (because it will be shipped with the JSP page to other processors all at once by some other team).

I know that JSP has the ability to run executables with relative paths because I could run this:

<form action="./my_executable_that_generates_a_dynamic_page">

However, I need this to run from a servlet to populate the dropbox using javascript.

<%= new File("./exec_produce_dropdown_list").getPath() %>

The above snippet gives me a different directory.

I've also tried:

<%= new File(new File(request.getServletContext().getRealPath(request.getRequestURI())).getParent().replace('\\', '/'), "exec_produce_dropdown_list"); %>

And this is pretty close except if there's a virtual path in the URI that doesn't correspond to the filesystem (which is what we have), it won't point to the right directory.

Is there a simple way for me to run the executable?? I also would like to add that there is no web.xml for me to work with.

THG
  • 312
  • 3
  • 13
  • What is the right directory? Where is file located? If it in your web app's root directory, then try using <%= application.getRealPath("/exec_produce_dropdown_list") %> for the path. – rickz Apr 06 '17 at 16:31
  • The real path does not correspond. I found my solution though, thanks. – THG Apr 06 '17 at 19:17

1 Answers1

2

Found my answer:

request.getRealPath(request.getServletPath())

Should give me the /path/in/filesystem/to/file.jsp

THG
  • 312
  • 3
  • 13
  • That method of the request object has been deprecated. You should use the application object as I posted. Anyway,I think you are mixing up file path and url. I think what you need to do is get the file path and then execute by way of something like the code at http://stackoverflow.com/questions/5604698/java-programming-call-an-exe-from-java-and-passing-parameters – rickz Apr 06 '17 at 20:11