• web.xml配置详解


    常用配置

      修改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>
  • 相关阅读:
    JAVA面试题
    Oracle入门笔记 ——启动进阶
    SQL 基础
    BZOJ 1507 Editor(块状链表)
    BZOJ 1018 堵塞的交通traffic(线段树)
    SPOJ 422 Transposing is Even More Fun(polay计数)
    BZOJ 2754 喵星球上的点名(后缀数组)
    POJ 1568 Find the Winning Move(极大极小搜索)
    Miller-Rabin素数测试学习小计
    Lucas定理学习小记
  • 原文地址:https://www.cnblogs.com/wuheng-123/p/13654314.html
Copyright © 2020-2023  润新知