日期:2014-05-17  浏览次数:20708 次

菜鸟求助呀:java servlet开发web:怎么让程序新加入的几句话在web浏览器中显示出来呢?
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Display extends HttpServlet {

/**
* @param args
*/
private static final long serialVersionUID=1L;
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
PrintWriter out=response.getWriter();
try{
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec("javac");
InputStream stderr=proc.getErrorStream();
InputStreamReader isr=new InputStreamReader(stderr);
BufferedReader br=new BufferedReader(isr);
String line=null;
out.println("<html>");
out.println("<font size=30 color=yellow>www.qisiren.org</font><br>");
out.println("<marquee>"+ new java.util.Date() +"</marquee>");

while((line=br.readLine())!=null)
out.println("<marquee>"+line+"</marquee>");
out.println("");
int exitVal=proc.waitFor();
out.println("<marquee> Process exitValue:"+exitVal+"</marquee>");
out.println("</html>"); }catch(Throwable t)
{
t.printStackTrace();
}
}


}
新加入的几句话:是红色的区域。可是在浏览器上显示的时候,都没有显示这一部分,是什么原因呢?
附加:我是菜鸟,现在看着书,学习编程序,有没有什么好的学习编程序的方法呀?我会追加分的哦~~
谢谢~~




------解决方案--------------------
InputStream stderr=proc.getErrorStream();
弄错了需要处理的Stream,所以后面br.readLine()阻塞了

改为:
InputStream stderr=proc.getInputStream();