String webBase = new File("src/main/webapp").getAbsolutePath();
Tomcat tomcat = new Tomcat();
tomcat.setPort(9002);
tomcat.setBaseDir(".");
StandardServer server = (StandardServer) tomcat.getServer();
AprLifecycleListener listener = new AprLifecycleListener();
server.addLifecycleListener(listener);
Context webContext = tomcat.addWebapp("/", webBase);
ErrorPage notFound = new ErrorPage();
notFound.setErrorCode(404);
notFound.setLocation("/index.html");
webContext.addErrorPage(notFound);
webContext.addWelcomeFile("index.html");
tomcat.start();
tomcat.getServer().await();embedded tomcat
最新推荐文章于 2024-11-08 15:38:56 发布
本文介绍如何使用Java代码配置Tomcat服务器,包括设置端口、基本目录、添加监听器、上下文路径、错误页面及欢迎文件等关键步骤。
4995

被折叠的 条评论
为什么被折叠?



