这是一个关于嵌入 jetty 7 的示例: http ://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
public class OneServletContext
{
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new HelloServlet()),"/*");
server.start();
server.join();
}
}
服务器 HelloServlet 将通过调用 init(ServletConfig config) 进行初始化;
如何告诉 Jetty 将我自己的 ServletConfig 传递给 HelloServet?(我没有 web.xml 文件,我也不想拥有)
Note:
I think that in Jetty6, you can call context.setInitParameter("my_key", "my_value");
but this function does not exists in Jetty7.
I've tried with context.getServletContext.setInitParameter("my_key", "my_value");
but I get an exception
java.lang.IllegalStateException was thrown.
org.eclipse.jetty.servlet.ServletContextHandler$Context.setInitParameter(ServletContextHandler.java:569)