Re[3]: mp3 converting
От: Alex-AKF  
Дата: 15.06.04 16:22
Оценка:
> просто есть опасения — как бы не вылетела основная JVM, где томкат
> работает...

O'Relly Java Servlet Programming

public class Finger extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String command = "finger";
Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
process = runtime.exec(command);
DataInputStream in = new DataInputStream(process.getInputStream());
// Read and print the output
String line = null;
while ((line = in.readLine()) != null) {
out.println(line);
}
}
catch (Exception e) {
out.println("Problem with finger: " +
ServletUtils.getStackTraceAsString(e));
}
}
}


This servlet uses the exec() command just like any other Java class would.
It executes the finger command, then reads and prints the output. If
there's a problem, the servlet catches an exception and prints the stack
trace to the user. This servlet assumes the finger command exists in the
default search path. If that isn't the case, change the command string to
specify the path where finger can be found.

We should point out that, although Java is executing native code when it
executes the finger program, it doesn't open itself up to the risks that
normally exist when executing native code. The reason is that the finger
program executes as a separate process. It can crash or be killed without
impacting the server executing the servlet.
Posted via RSDN NNTP Server 1.9 beta
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.