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

关于jsp的问题
小弟才开始学习jsp,我看书说,service方法会自动去调用相应的do方法,但是我这样写了之后,应该是重载了doget方法啥,但是为什么没有打印出doget方法中得helloWorld呢?

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 HelloWorldServler extends HttpServlet{

private static final long serialVersionUID = 1L;



@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

}



protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter pw = resp.getWriter();
pw.write("<html><head><title>yeliguo</title></head><body>helloWorld</body></html>");
pw.flush();
pw.close();
}

}

------解决方案--------------------
你重写了service方法 请求到达时会调用你重写的service 但是你service啥都没做
Java code
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}