gpt4 book ai didi

javascript - 从 jsp 页面执行 bash 脚本

转载 作者:行者123 更新时间:2023-11-28 22:38:15 25 4
gpt4 key购买 nike

我以前写过一个执行 java 类的 bash 脚本,它在运行该类之前会进行其他检查。运行时需要参数; ./SyncIPs.cmd 10.0.1.45 并执行一些命令。

我正在尝试使用 html/javascript 按钮在 jsp 页面中运行此脚本。到目前为止,我有两个 jsp 文件如下:

门户.jsp:

      <%
if(request.getParameter("submitted")==null)
{

if(check)
{

%><%@include file="Sync.jsp" %><%
}
else
{

%><%@include file="Sync.jsp" %><%
}
}
%>

同步.jsp:

   <%
if(request.getParameter("submit") == null)
{

%>
<div class=display>this is the Sync</div>

</div>

<br>
<form method="POST" action="/project/jsp/Portal.jsp" id=form2>


<input type=hidden name=sync>
<!---this is where I want my script to be run from,--->

<input type="button" value="" name="submit" action="run"
onClick="if(runOnSubmit()){getSomethingWithAjax
('Portal.jsp'+getAllFormElementsAndMakeIntoURI(true),
'','hereIsTheMainHeaderSpan',false,false);}">
<%
}//end if
%>

如何让此脚本运行并发布到 portal.jsp 页面上?

最佳答案

你必须在你的 .jsp 中放入一些 java 代码

try {
Process p = Runtime.getRuntime().exec("/path_to_your_script/SyncIPs.cmd 10.0.1.45");
p.waitFor();
System.out.println("exit code: " + p.exitValue());
} catch (Exception e) {
System.out.println(e.getMessage());
}

注意:注意可能的安全问题

关于javascript - 从 jsp 页面执行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12699025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com