<p>若是在一個應用中嵌入一個jetty </p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:44d9d94c-7d33-46c3-949e-ef8097cbb8f3" class="wlWriterEditableSmartContent"><pre class="brush: java; gutter: true; first-line: 1; tab-size: 4; toolbar: true; width: 885px; height: 303px;" style=" width: 885px; height: 303px;overflow: auto;">public class OneServletContext { public static void main(String[] args) throws Exception { Server server = new Server(8080);java
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()),"/*"); context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*"); context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*"); server.start(); server.join(); }
}</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>web
<p>HelloServlet 類是能夠訪問應用中的資源的 </p>app
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:3bcff60e-bb88-42f2-8be0-05caf5fa9ac8" class="wlWriterEditableSmartContent"><pre class="brush: java; gutter: true; first-line: 1; tab-size: 4; toolbar: true; width: 885px; height: 331px;" style=" width: 885px; height: 331px;overflow: auto;">public class ManyContexts { public static void main(String[] args) throws Exception { Server server = new Server(8080);webapp
WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/ctx1"); webapp.setWar(jetty_home+"/webapps/test.war"); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { webapp }); server.setHandler(contexts); server.start(); server.join(); }
}</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>code
<p>test.war 中的類是不能訪問到應用中的資源的</p>orm