这可以返回一个字符串:
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class MonkeyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("got this far");
}
}
但是我无法获取返回的html文档。这不起作用:
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class BlotServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("html/mypage.html");
}
}
很抱歉成为菜鸟!
编辑:
我已经在单独的文档中使用了html。所以我需要返回文档,或者以某种方式读取/解析它,所以我不只是重新输入所有的html …
编辑:
我的web.xml中有这个
Monkey
com.self.edu.MonkeyServlet
Monkey
/monkey
还有其他我可以放的东西,所以它只是返回一个文件,例如…
Monkey
blot.html