Actually ,i had use Process and Runtime class to create a jar file. I invoke the jar file in my jsp page. But, it does not work! Below is my class file and jsp file:
java class file:
package serveradmin;
/*
*
* Created on February 28, 2007, 10:32 AM
*/
import java.util.*;
import java.io.*;
public class Main
{
static class PipeInputStreamToOutputStream implements Runnable
{
PipeInputStreamToOutputStream(InputStream is, OutputStream os)
{
is_ = is;
os_ = os;
}
public void run()
{
try
{
byte[] buffer = new byte[1024];
for(int count = 0; (count = is_.read(buffer)) >= 0;)
{
os_.write(buffer, 0, count);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
private final InputStream is_;
private final OutputStream os_;
}
public void runSH()
{
try
{
String dir = System.getProperty("user.home");
String[] command = {"sh","-c", "./mk.sh"};
final Process process = Runtime.getRuntime().exec(command);
new Thread(new PipeInputStreamToOutputStream(process.getInputStream(), System.out)).start();
new Thread(new PipeInputStreamToOutputStream(process.getErrorStream(), System.err)).start();
int returnCode = process.waitFor();
System.out.println("Return code = " + returnCode);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
jsp file:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean class="serverAdmin.Main" id="serverAdmin" scope="session"/>
<html>
<head><title>Index JSP</title></head>
<body>
<%serverAdmin.runSH();%>
</body>
</html>
mk.sh:
mkdir test/test.txt
Thus, can u kindly show me an eample?
TQ for the reply. :)