url--web路径

1.servlet   url匹配规则

容器会将http://localhost/tes去掉,将剩下的/aaa.html部分拿来做servlet的映射匹配
而且每次匹配最终都只匹配一个 servlet

servletA的url-pattern为/test/*,而servletB的url-pattern为/test/a/*,此时访问http://localhost/test/a时,容器会选择路径最长的servlet来匹配,也就是这里的servletB

“/”是servlet中特殊的匹配模式,切该模式有且仅有一个实例,优先级最低,不会覆盖其他任何url-pattern,只是会替换servlet容器的内建default servlet ,该模式同样会匹配所有request。

/代表拦截所有的请求排除jsp


/test/*.action为不合法的url-pattern    只能进行路径匹配或/test   或   .jsp后缀名匹配
一般做全匹配时,servlet的url-pattern 为 / 。filter的url-pattern 为 /* 。
 


filter 匹配会多个匹配,符合规则的都进

filter url-pattern 为 / 不生效


2 sprimvc 静态资源交由默认的servlet去处理
    <mvc:default-servlet-handler/>
    <mvc:annotation-driven></mvc:annotation-driven>



获取web路径
真实物理路径

request.getSession().getServletContext().getRealPath("/");

String relativelyPath=System.getProperty("user.dir");

类路径
hread.currentThread().getContextClassLoader().getResource("").getPath();


InputStream is=TestAction.class.getClassLoader().getResourceAsStream("test.txt");



<Context path="/dts6"  docBase="D:JIT_workspacesworkspace_defaultdts6WebContent" />


<locale-encoding-mapping-list>
        <locale-encoding-mapping>
            <locale>zh</locale>
            <encoding>UTF-8</encoding>
        </locale-encoding-mapping>
    </locale-encoding-mapping-list>









原文地址:https://www.cnblogs.com/jentary/p/12033966.html