Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to invoke shell script from JSP page

858325Jun 6 2011 — edited Jun 6 2011
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2011
Added on Jun 6 2011
5 comments
5,638 views