我需要以編程方式添加和刪除Jetty 6服務器上的servlet。 雖然它幾乎直接添加我找不到有效的方法來刪除。 對我而言,添加和刪除servlet非常重要,因爲它與動態組件體系結構相關聯。當我添加一個組件時,我需要添加一項新服務,而當我刪除該組件時,我需要刪除該服務。碼頭6:如何刪除Servlet?
要添加我用這個模式一個servlet:
Server server = new Server(8080);
class MyServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.getOutputStream().write("Hello World!".getBytes());
}
}
...
public void addServlet(HttpServlet s, String path)
{
Context root = new Context(server,"/",Context.SESSIONS);
root.addServlet(new ServletHolder(new MyServlet()), "/test/*");
root.getServletHandler().
}
public void removeServlet(HttpServlet s, String path)
{
//What I have to put here ? There is no removeServlet like methods in server/Context/ServletHolder
}
爲什麼刪除一個servlet就不那麼明顯了?你能向我解釋動機嗎?
對於項目限制,我不能移動到碼頭7或8 ......無論如何感謝。 – alexroat 2012-03-20 13:22:10
在開始時我實際上使用了處理程序,爲了提供與現有解決方案的交叉兼容性,我需要移動到標準的java servlet。 – alexroat 2012-03-20 13:23:41