简体   繁体   English

为什么我的jsp中不能使用核心taglib?

[英]Why can't I use core taglib in my jsp?

I'm having trouble when I include the taglib in my jsp. 我在jsp中包含taglib时遇到了麻烦。 When I launch tomcat, it errors with the following report. 当我启动tomcat时,以下报告出错。

The particular line that makes it go from working to not working is this 使它从工作变为不工作的特定行是这样的

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

Complete code is included below. 完整的代码包含在下面。

I'm aware there are many similar questions, but all the one's I've found have been resolved by adding the jstl dependency to the pom file. 我知道有很多类似的问题,但是我发现的所有问题都已通过将jstl依赖项添加到pom文件中而得到解决。 I've already done that and am still facing the same issue. 我已经做到了,仍然面临着同样的问题。

index.jsp index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Testing</h1>
<c:redirect url="/home.jsp" />
</body>
</html>

pom.xml pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Testing</groupId>
    <artifactId>Testing</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>AlphaProject</name>
    <description>Test run anything tricky here before applying to main project</description>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

Output 输出量

Message: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

Description: The server encountered an internal error that prevented it from fulfilling this request.

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:277)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:75)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTldResourcePath(TagLibraryInfoImpl.java:243)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:124)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:411)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469)
    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:580)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
    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)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Try adding below maven dependencies in your pom.xml : 尝试在pom.xml添加以下Maven依赖项:

<!-- standard.jar --> 
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

<!-- JSTL --> 
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.1.2</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM