• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime().exec() in a Servlet executing another java class  RSS feed

 
Fox Nesn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Long time lurker, first time poster. I am working on a Java web application using JSP and Servlets. In the class that extends HttpServlet form data is read using doPost and those values are written to a file called userinput.dat. Then I have the following block execute another class file located in the same physical directory as the servlet class file.



neuralModified is a compiled class file that runs some heavy business logic.

the servlet creates the userinput.dat file without issue and does not throw any errors when run. however it never executes "java neuralModified." i know this because neuralModified should write its own file with completed results but does not. (NOTE: I did check to make sure the file was not created in another directly.)

using the same try/catch block in a class that does not extend HttpServlet the code works perfectly. My guess is that the Servlet thinks neuralModified is in another location but how can I know this if it does not throw any error?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason you're executing the Java class in a separate process rather than just bringing it into the web app?
 
Fox Nesn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Is there a reason you're executing the Java class in a separate process rather than just bringing it into the web app?


Yes. neuralModified is a class file that cannot be run inside a webapp. It is a separate business process I want to keep out of the Servlet entirely.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fox Nesn wrote:Yes. neuralModified is a class file that cannot be run inside a webapp. It is a separate business process I want to keep out of the Servlet entirely.

Why not, and why?
 
Fox Nesn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Fox Nesn wrote:Yes. neuralModified is a class file that cannot be run inside a webapp. It is a separate business process I want to keep out of the Servlet entirely.

Why not, and why?


the httpservlet class pulls values from a web form. it stores those values in strings which need to be passed to neuralModified for processing. neuralModified has methods which return values. methods that return values cannot exist inside the doPost method. if they exist outside the doPost method they cannot access the form values stored using request.getParameter inside doPost because you cannot declare those variables as public. instead, i would have the servlet pull the form data and create a file. then execute "java neuralModified" which reads that file and does processing.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, that really doesn't make much sense. So my suggestion would be that we should get rid of the Runtime.exec() workaround and try to produce a solution to your original problem.
 
Fox Nesn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm sorry, that really doesn't make much sense. So my suggestion would be that we should get rid of the Runtime.exec() workaround and try to produce a solution to your original problem.


Here is the basic issue. I wrote a client based java application that reads input from the keyboard, takes that input and performs calculations on it and returns a result. Basic stuff if I take out all the neural network mumbo jumbo. Instead of having the program read input from a keyboard, I want it to read the input from a web form. I figured I would simply extend the client application with HttpServlet, and put in the request.getParameter values inside doPost(). However calling the request.getParameters outside of doPost is impossible since those variables cannot be declared public and thus scene by methods outside of doPost.

So it is something similiar to this...



In this manner the values a,b,c, are not valid because they are declared in doPost(). Any help is appreciated!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!