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方法拾取。
感謝任何幫助。提前致謝。