1

我正在为从文本输入读取并将变量值作为参数传递给 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");
4

1 回答 1

1

你想要的是:

Process p = Runtime.getRuntime().exec("/root/script.cmd " + myArgument );

PS实际上,在声明myArgument之后
,我看不到您在哪里为它赋值:
String myArgument = "";


不是很相关,但你正在做一种 PHP 风格。阅读:https ://stackoverflow.com/a/3180202/814702

于 2013-01-12T00:23:37.477 回答