日期:2014-05-18  浏览次数:20618 次

jsp中servlet的runtime问题
servlet中能用Runtime吗
问题补充:如果能.  
package   test;  
import   java.io.IOException;  
import   java.io.PrintWriter;  
import   javax.servlet.ServletException;  
import   javax.servlet.http.HttpServlet;  
import   javax.servlet.http.HttpServletRequest;  
import   javax.servlet.http.HttpServletResponse;  
public   class   Test   extends   HttpServlet   {  
protected   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)  
throws   ServletException,   IOException   {  
int   i=0;  
Runtime   r   =   Runtime.getRuntime();  
String   str= "start   C:\\WINDOWS\\system32\\notepad.exe ";  
try  
{  
while(i!=3)  
{  
r.exec( "cmd   /c   "+str);  
i++;  
}  
}  
catch(IOException   e){}  
PrintWriter   out=response.getWriter();  
i=0;  
while(i!=3)  
{  
out.println( " <html> <body> <h1> This   is   a   servlet   test. </h1> </body> </html> ");  
i++;  
}  
out.flush();  
}  
}  

上面的那段代码为什么没有打开记事本???

------解决方案--------------------
@_@,new 出来调用就行了,