我正在为从文本输入读取并将变量值作为参数传递给 bash 文件的 JSP 页面编写此代码,但似乎 bash 文件不接受变量,它仅在我传递实际值时才有效的变量。如何将变量传递给这个 bash 文件?这是代码:
<%
String myArgument = "";
if (request.getParameter("submit")==null)
{
%>
<form method="POST" action="/tomcat/webapps/project/jsp/runCMD.jsp" id=form2>
<input type=text id=first value="${first}" Title="IP adress here" >
<input type="submit" value="Submit Changes" name="submit"
onClick="if(runOnSubmit()){getSomethingWithAjax('ChangeIP.jsp'+
getAllFormElementsAndMakeIntoURI(true),'',
'hereIsTheMainHeaderSpan',false,false);}">
<%
}//end if
//else if submitted
else {
request.setAttribute("myArgument", myArgument);
try {
Process p = Runtime.getRuntime().exec("/root/script.cmd myArgument );
p.waitFor();
System.out.println("Waiting for the System to reboot" + p.exitValue());
} catch (Exception e) {
System.out.println(e.getMessage());
out.println("There was an error while submitting ");
}
}//end else
%>
请注意,当将值传递给脚本时,它会使用以下代码执行:
Process p = Runtime.getRuntime().exec("/root/changeip.cmd 10.0.100.18");