Results 1 to 4 of 4
  1. #1
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

    Default Webservice to start an executable file

    Hi, I have a servlet and jsp which am using to start an executable file from jsp. Now my requirement is I have to do the same thing using REST API. ie I have to create a webservice to start an executable file from a web page. Any help is appreciated. My code snippet for servlet and jsp below.

    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
    IOException {

    try{

    PrintWriter out = res.getWriter();

    String browsefile = req.getParameter("browsefile");

    if(browsefile == null || browsefile.equals("")){
    out.println("File does not exist");

    throw new ServletException("File Name can't be
    null or empty");

    }

    File file = new File("C:/lic/test.li");
    // File file = new File("C:/apache-tomcat-
    7.0.42/webapps/Lic/test.li");

    if(!file.exists()){
    out.println("File does not exist");

    throw new ServletException("File doesn't exists
    on server.");

    }

    res.setContentType("text/html;charset=UTF-8");


    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec
    ("C:\\tools\\server\\grd.exe" );

    BufferedReader stdInput = new BufferedReader(new
    InputStreamReader(pr.getInputStream()));
    BufferedReader input = new BufferedReader(stdInput);
    String serverstarted="";
    StringBuffer startOutput = new StringBuffer();
    while((serverstarted = input.readLine()) !=
    null){
    startOutput.append(serverstarted
    + "\n");
    }

    req.setAttribute("startOutput",
    startOutput.toString());
    req.getRequestDispatcher
    ("grdoptions.jsp").forward(req, res);
    }catch (Throwable t)
    {
    t.printStackTrace();
    }


    finally {

    } }

    }JSP:

    <form action="start" METHOD="GET" enctype="multipart/form-data">
    <input type="file" name="browsefile" />
    <input type="submit" name="start"
    value="StartServer" />
    </form>

    <div id="result">
    <pre>
    ${requestScope.startOutput}
    </pre>
    </div>Web.XML:

    <servlet>
    <servlet-name>Start</servlet-name>
    <servlet-class>com.abc.lic.Start</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>Start</servlet-name>
    <url-pattern>/start</url-pattern>
    </servlet-mapping>

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Webservice to start an executable file

    I don't see where you have even made an attempt. Try Google "Java Jax-RS tutorial".

  3. #3
    KKG
    KKG is offline Member
    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0

    Default Re: Webservice to start an executable file

    i did made an attempt. this is wat am doing but I don't see any output. Below is my service class
    @Path("/start")

    public class StartService {


    @SuppressWarnings("resource")
    @GET
    @Path("/logfile")
    @Produces(MediaType.TEXT_XML)


    public String getLog()
    {
    String line = null;

    String status = null;
    OpenLog openlog = new OpenLog();
    status = openlog.openLogFile(line);
    return status;

    }


    }

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Webservice to start an executable file

    I have NO IDEA what "OpenLog" is and why are you passing it a null value?

Similar Threads

  1. how to post xml file through webservice
    By jackjeryes in forum Networking
    Replies: 0
    Last Post: 05-04-2011, 02:07 PM
  2. create windows executable using executable jar file
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 09:29 PM
  3. Executable jar file
    By franklyn@bellsouth.net in forum New To Java
    Replies: 12
    Last Post: 08-26-2010, 02:03 PM
  4. Executable File.
    By BeeGee in forum Advanced Java
    Replies: 13
    Last Post: 05-25-2010, 01:35 PM
  5. Getting WebService Annotations in a .class file.
    By carlo@CCS in forum Advanced Java
    Replies: 0
    Last Post: 10-08-2009, 12:13 AM

Posting Permissions

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