前不久接手了一个老古董项目, 本地启动的时候报错The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar。虽然tomcat启动成功了, 但是浏览器一访问页面就是这个错误提示,始终绕不过去。
     
   
    这个是因为页面用了jstl标签库,如
    
     <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    
    之类,但它现在找不到所以会报错,提示了你web.xml或者jar的问题。
    
     
   
排查方法:
    1.检查tomcat安装目录的lib文件夹下面是否有jstl.jar和standard.jar这两个包,没有就放上,重启tomcat。
    
    2.将jstl.jar和standard.jar放到项目的WEB-INF的lib下面,然后构建路径,重启tomcat。
   
    
     上面这两步是排查jar问题,如果还不行,说明jar里面应该没有tld文件。那接下来开始web.xml排查,咱手动指定c.tld的路径。
    
   
3.检查web.xml里面是否有如下taglib标签,没有的话就加上
<jsp-config>
     <taglib>
        <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
        <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://java.sun.com/jsp/jstl/functions</taglib-uri>
        <taglib-location>/WEB-INF/fn.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
        <taglib-location>/WEB-INF/fmt.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://www.springframework.org/tags/form</taglib-uri>
        <taglib-location>/WEB-INF/spring-form.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/struts-tags</taglib-uri>
        <taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
    </taglib>
     <!-- 以上比较常用的5个标签根据自己项目需要加,项目中用到的必须加上(如果还使用了别的标签库也需加上) -->
  </jsp-config>
    并在项目的/WEB-INF/目录下放上c.tld这个文件(web.xml里配置了的tld都要放上,不然运行时在这个路径下找不到这些tld也是报错的),tld文件一般把那两个jar右键解压后能找到,么有的话去网上找个来。
    
    
    
    经过这三步的检查,项目应该就可以访问看到正常的页面了。
   
另外多说一点别的东西,上面只说到了常用的5个标签库,其他的还有哪些呢。比如下面这个
    
    
    sitemesh
   
    
    
    需要的是sitemesh-2.2.1.jar,包中的META-INF\目录下有sitemesh-decorator.tld、sitemesh-page.tld,剩余的操作跟上面jstl一样。
   
<taglib>
	<taglib-uri>sitemesh-page</taglib-uri>
	<taglib-location>
		/WEB-INF/sitemesh-page.tld
	</taglib-location>
</taglib>
<taglib>
	<taglib-uri>sitemesh-decorator</taglib-uri>
	<taglib-location>
		/WEB-INF/sitemesh-decorator.tld
	</taglib-location>
</taglib>
    sitemesh就是把请求结果
    
     处理后
    
    再返回给浏览器,基于Servlet的filter实现。所以web.xml里面也是要配置过滤器
   
<filter>
    <filter-name>sitemeshFilter</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemeshFilter</filter-name>
    <url-pattern>/myaccount/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>sitemeshFilter</filter-name>
    <url-pattern>/admin/*</url-pattern>
  </filter-mapping>
   <!-- 其他需要拦截处理的路径,可以继续配... ,也可以直接配/* 处理所有-->
而且/WEB-INF/下面需要有个decorator.xml文件,decorator.xml内容以及含义如下
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/你的jsp的存放路径">
    <decorator name="frame" page="frame.jsp">  <!--  name自定义名,page装饰文件 -->
        <pattern>/*</pattern> <!--  需要处理的路径:全部 (也可以指定详细的路径,可配置多个)-->
    </decorator>
</decorators>
    
    
    shior
   
shior是一个权限框架,需要的包是shiro-all-1.3.2.jar,包里面有shiors.tld,web.xml可参考如下
<filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
其他的标签库,也不详细说了,只列举一下,解决方法照葫芦画瓢。
- 
     
 oscache
 
 :oscache-2.3.jar。报错提示: The absolute uri: http://www.opensymphony.com/oscache cannot be resolved in either web.xml or the jar
- 
     
 displaytag
 
 :displaytag-1.1.1.jar。报错提示: http://displaytag.sf.net cannot be resolved in either web.xml or the jar files
- 
     
 struts-menu
 
 :struts-menu-2.4.3.jar。报错提示: http://struts-menu.sf.net/tag-el cannot be resolved in either web.xml or the jar files
- 
     
 acegi-security
 
 :acegi-security-1.0.5.jar.acegi-security-tiger-1.0.5.jar。报错提示: The absolute uri: http://acegisecurity.org/authz cannot be resolved in either web.xml or the jar files
 
