I am new to jsp and runtime. I need to be able to run a script with a button on a web application page. The location of the script is in /home/user/ejbca_4/bin and to run it,
cd ejbca_4/bin
./ejbca.sh batch
Someone recommended to put these commands in a .sh file in /home/user/bin . I created /home/user/bin/test.sh with the following contents:
#!/bin/bash
cd ejbca_4/bin
./ejbca.sh batch
I added this to the jsp page
<input type="submit" name="Generate test" value='<c:out value="Generate Test"/>' tabindex="<%=tabindex++%>"
onClick='generate()'>
function generate() {
Process proc = Runtime.getRuntime().exec("test.sh",null,null);
}
but somehow this gave a NumberFormatException. I removed Process proc:
function generate() {
Runtime.getRuntime().exec("test.sh",null,null);
}
and there was no NumberFormatException. However, the the script was not run. Can anyone explain how this should be done?
You need to understand which part of your code is running on the server and which part is running on the client(browser). And you should never put code that should be run on the server into the client side, because that won’t work(obviously).
In your case, code that should be run on the server is:
It should be surrounded by
<% %>And the client side code is: