Results 1 to 8 of 8
  1. #1
    rajesh4851 is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default How to invoke shell script from JSP page

    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 :

    Java 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 :

    Java Code:
    echo ' Done successfully ' > testfile.txt
    When 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.
    Please help me out .

    Regards,
    Rajesh

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    But what do you expect that it would have shown?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    rajesh4851 is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    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?
    Last edited by rajesh4851; 06-06-2011 at 11:15 AM.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    the directory where the jsp page is created in unix box
    Who tell it you? it will be created in folder there you run your web service. for example tomcat/bin/
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    rajesh4851 is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    Its working when i give complete path prefix to my shell script like this...
    String unixCommand = "/u04/..../sh test.ksh";
    Thanks to all.

  6. #6
    manish29 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Re: How to invoke shell script from JSP page

    And the File testfile.txt can be found under tomcat log folder - true when i ran the same Script

  7. #7
    rajesh4851 is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default Re: How to invoke shell script from JSP page

    Thanks Manish..!!

  8. #8
    ravin1987 is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Re: How to invoke shell script from JSP page

    Guys, i am having the same problem as Rajesh. Could you please guide me on this.

    Should i keep the shell script in the Unix directory or Windows where my apache is running.
    Also in the path, which path should be given?

    Please reply ASAP

Similar Threads

  1. Problem to invoke webbeans from JSF page
    By gscoelho in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 02-26-2011, 04:41 PM
  2. Java Applet Shell script
    By karthikm897 in forum Java Applets
    Replies: 5
    Last Post: 08-18-2009, 04:42 AM
  3. Replies: 1
    Last Post: 02-26-2009, 07:46 AM
  4. Replies: 0
    Last Post: 02-16-2009, 08:05 AM
  5. How to generate auto shell script using java..
    By balakrishna in forum Advanced Java
    Replies: 8
    Last Post: 12-30-2008, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •