1
问题:只有在doPet被调用时才会调用doGet。Embedded Jetty doGet调用,预计doPost
我有我开始作为一个嵌入式Jetty服务器如下:
server = new Server(8080);
ServletContextHandler myContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
myContext.setContextPath("/Test.do");
myContext.addServlet(new ServletHolder(new MyServlet()), "/*");
ResourceHandler rh = new ResourceHandler();
rh.setResrouceBase("C:\\public");
HandlerList hl = new HandlerList();
hl.setHandlers(new Handler[]{rh, myContext});
server.setHandler(hl);
//server.start() follows
我启动服务器后,我打开如下页面(驻留在“公共”文件夹,并通过http://localhost:8080/test.html打开):
<html>
<head><title>Test Page</title></head>
<body>
<p>Test for Post.</p>
<form method="POST" action="Test.do"/>
<input name="field" type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
当我按提交按钮,我期待我的servlet的doPost方法被调用,但doGet似乎被调用。 MyServlet类(延伸的HttpServlet)包含:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
System.out.println(" doGet called with URI: " + request.getRequestURI());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
System.out.println(" doPost called with URI: " + request.getRequestURI());
}
我从来没有得到过的doPost打印,距离的doGet一个(上提交按钮按下)。
显然,码头(和网络技术在一般)是全新的我。我一直在梳理Jetty的例子,但似乎无法获得POST实际上被doPost方法拾取。
感谢任何帮助。提前致谢。