在JSP页面中执行bash脚本 [英] executing a bash script from a jsp page
问题描述
我有previously写了执行Java类中的bash脚本,它运行在课前做其他检查。
运行时需要的参数; ./ SyncIPs.cmd 10.0.1.45
并执行一些命令。
I have previously written a bash script that executes a java class, it does other checks before running that class.
when running it takes arguments; ./SyncIPs.cmd 10.0.1.45
and executes few commands.
我试图运行使用的HTML / JavaScript的按钮在JSP页面中此脚本。我到目前为止,两个JSP文件如下:
I am trying to run this script in a jsp page using a html/javascript button. I have so far, two jsp files as follows:
portal.jsp:
portal.jsp:
<%
if(request.getParameter("submitted")==null)
{
if(check)
{
%><%@include file="Sync.jsp" %><%
}
else
{
%><%@include file="Sync.jsp" %><%
}
}
%>
Sync.jsp:
Sync.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页面上?
How do I get this script to run and get posted on the portal.jsp page?
推荐答案
您必须把一些Java code在你的.jsp
You have to put some java code in your .jsp
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());
}
请注意:注意可能出现的安全问题
NOTE: be aware of possible security issues
这篇关于在JSP页面中执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!