通过Jetty搭建一个简单的Servlet运行环境(二)

2014-11-24 09:17:09 · 作者: · 浏览: 1
atch (Exception ex) {
log.error("Failed to run Jetty Server", ex);
throw ex;
}
}
在JettyLauncher运行后,我们可以访问http://localhost:7411/ping来查看Jetty是否成功运行. http://localhost:7411/ping将运行以下Spring MVC Servlet:
[java]
@Controller
public class TestServlet {
private static Logger log = Logger.getLogger(TestServlet.class);
@RequestMapping(value="/ping", method = RequestMethod.GET)
public void ping(HttpServletResponse response) throws IOException {
log.info("ping page is called");
IOUtils.write("Embedded Jetty Server is Up and Running", response.getOutputStream());
}
}
通过Jetty,我们可以很容易的在本地运行和调试Servlet,而生成好的Servlet我们可以直接发布到Tomcat. 这样,我们可以简化Servlet的开发和调试.