常用配置
修改web应用默认首页
<welcome-file-list> <welcome-file>index.html</welcome-file>//写首页的名称就行了 </welcome-file-list>
Servlet通配符映射及初始化参数
<servlet> <servlet-name>patternServlet</servlet-name> <servlet-class>com.imooc.pattern.Employer</servlet-class> </servlet> <servlet-mapping> <servlet-name>patternServlet</servlet-name> <url-pattern>/employer/*</url-pattern> </servlet-mapping> String url = request.getRequestURI(); System.out.println(url); String employerId = url.substring(url.lastIndexOf("/")+1); System.out.println(employerId); if(employerId.equals("1")) { response.getWriter().println("wuyi"); }
全局配置
<context-param> <param-name>content</param-name> <param-value>© 2020 imooc.com 京ICP备 12003892号-11</param-value> </context-param> ServletContext context = request.getServletContext(); String content = context.getInitParameter("content"); context.setAttribute("content", content); context.setAttribute("title", "<h1>幕课网</h1>"); response.setContentType("text/html;charset=utf-8"); response.getWriter().println("ServletContext 学习");
设置 404、500等状态码默认页面
<!-- 指定错误页面 --> <error-page> <error-code>404</error-code> <location>/error/404.html</location> </error-page>