How to invoke shell script from JSP page
858325Jun 6 2011 — edited Jun 6 2011Hi Friends,
I am a beginner to java/jsp. I have one shell script, that needs to be invoked from my jsp page. Here is the code in my page - testjava.jsp :
Code:
<%@page language="java" %>
<%@page import="java.util.*" %>
<html>
<head>
<%
String unixCommand = "sh test.ksh";
Runtime rt = Runtime.getRuntime();
rt.exec(unixCommand);
System.out.println("Print Test Line.");
%>
</head>
<body>
</body>
</html>and my test.ksh contains the below code :
Code:
echo ' Done successfully ' > testfile.txtWhen i call this page from my website "http://132.17.34.101:7777/tools/testjava.jsp" it is showing blank and the shell script is not executed.
My expected out put is this:
When i copy this link "http://132.17.34.101:7777/tools/testjava.jsp" in browser and hit enter then it should call my shell script and testfile.txt should be created on that directory (the directory where the jsp page is created in unix box).
Also , pls let me know whats wrong in that code?
Please help me out .
Regards,
Rajesh