tomcat8和7关于自定义tag的处理区别
今天将一直运行在tomcat-7.0.29(jdk1.6)上的应用迁移到tomcat-8.0.26(jdk1.7)上面,老显示如下错误:
org.apache.jasper.JasperException: /clientLogin.jsp (line: 4, column: 0) null org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:91) org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:325) org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:358) org.apache.jasper.compiler.Parser.parseDirective(Parser.java:461) org.apache.jasper.compiler.Parser.parseElements(Parser.java:1430) org.apache.jasper.compiler.Parser.parse(Parser.java:139) org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227) org.apache.jasper.compiler.ParserController.parse(ParserController.java:100) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199) org.apache.jasper.compiler.Compiler.compile(Compiler.java:356) org.apache.jasper.compiler.Compiler.compile(Compiler.java:336) org.apache.jasper.compiler.Compiler.compile(Compiler.java:323) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
经过多方研究试验,终于找到原因,原来:自定义标签uiviewTag的定义方式是这样的:
<tlib-version>1.0</tlib-version> <jsp-version>1.0</jsp-version> <short-name>uiviewTag</short-name> <uri>/uiviewTag</uri> <description>页面上的特殊标签</description>
web.xml
<taglib> <taglib-uri>/uiviewTag</taglib-uri> <taglib-location>/WEB-INF/tlds/uiviewTag.tld</taglib-location> </taglib>
而在jsp引入的时候是这样的(tomcat-7.0.29),但运行正常:
<%@ taglib uri="uiviewTag" prefix="uiviewTag"%>
注意,uri="uiviewTag"并没有斜杠"/",在tomcat-8.0.26里面必须带斜杠:
<%@ taglib uri="/uiviewTag" prefix="uiviewTag"%>
否则就会报上述错误,不知道tomcat8稳定版是否有此问题。
看来版本升级也会暗藏玄机啊。