使用jstl时,没有web.xml的嵌入式Tomcat会引发异常

时间:2014-02-18 21:54:12

标签: java jsp jstl embedded-tomcat-7

我有一个Swing-App,可以启动没有web.xml的嵌入式tomcat7服务器。我加载了一个使用jstl的jsp。当我访问jsp时,我在Swing-App中出现了这个错误:

18.02.2014 22:32:54 org.apache.jasper.compiler.WebXml <init>
WARNUNG: Internal Error: File /WEB-INF/web.xml not found
18.02.2014 22:32:54 org.apache.jasper.compiler.WebXml <init>
WARNUNG: Internal Error: File /WEB-INF/web.xml not found
18.02.2014 22:32:54 org.apache.catalina.core.ApplicationDispatcher invoke
SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: The absolute uri: http://www.irquest.com/irq cannot be resolved in either web.xml or the jar files deployed with this application

在jsp中我使用这些taglibs:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

我使用jstl 1.1.2和标准1.1.2。这些库包含在我的pom中:

<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

这是我配置上下文的方式:

Context jqs3context = null;
        try {
            jqs3context = tomcat.addWebapp("/" + servletContainerSettings.getServletContext(), servletContainerSettings.getHtdocsHome());
        } catch (ServletException e) {
            e.printStackTrace();
        }
        Wrapper wrapper = Tomcat.addServlet(jqs3context, "JQS3", servletContainerSettings.getServletClass());

        //[..] wrapper init params here [..]

        jqs3context.addServletMapping("/" + servletContainerSettings.getServletName() + "/*", "JQS3");
        jqs3context.setCrossContext(true);
        jqs3context.setLoader(new WebappLoader());
        jqs3context.setResources(new FileDirContext());
        jqs3context.getNamingResources().addResource(createDatabaseResource("jdbc/iradmindb"));

这是在我将嵌入式tomcat5.5升级到tomcat7之后发生的。 我无法弄清楚为什么我会收到这个错误。我错过了什么?

1 个答案:

答案 0 :(得分:0)

回答我自己的问题:

在摆弄JarScanner并阅读文档(https://tomcat.apache.org/tomcat-7.0-doc/config/jar-scanner.html)后,这对我有用:

StandardJarScanner jarScanner = new StandardJarScanner();
jarScanner.setScanBootstrapClassPath(true);
jarScanner.setScanClassPath(true);
jqs3Context.setJarScanner(jarScanner);