問題:doPostが呼び出されることを期待している場合、doGetのみが呼び出されます。
次のように起動する組み込みの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
サーバーを起動した後、次のページを開きます( "public"フォルダーにあり、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>
[送信]ボタンを押すと、サーブレットの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(および一般的なWebテクノロジー)は私にとってまったく新しいものです。私はJettyの例をくまなく調べてきましたが、実際にdoPostメソッドによって取得されるPOSTを取得できないようです。
助けに感謝します。前もって感謝します。