简体   繁体   English

包括JSTL到Maven项目

[英]Include JSTL to maven project

This is my pom.xml: 这是我的pom.xml:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    <scope>provided</scope>
</dependency>

web.xml: web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       version="3.0">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
    <welcome-file>startPage.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/servlet</url-pattern>
</servlet-mapping>

and startPage.jsp 和startPage.jsp

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

but when I trying to open page, I recieve exception: 但是当我尝试打开页面时,我收到了异常:

HTTP Status 500 - 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 HTTP状态500-绝对uri: http : //java.sun.com/jsp/jstl/core不能在web.xml或与此应用程序一起部署的jar文件中解析

What is i am doing wrong? 我在做什么错? Thanks for help. 感谢帮助。

It seems its happening beacause of scope you defined as <scope>provided</scope> 似乎是因为您定义为<scope>provided</scope>

remove <scope>provided</scope> and give a try 删除<scope>provided</scope>并尝试

Below is the description for provided scope from Maven 以下是Maven提供的范围的说明

provided 提供

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. 这很像编译,但是表明您希望JDK或容器在运行时提供依赖项。 For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. 例如,在为Java Enterprise Edition构建Web应用程序时,您将对Servlet API和相关Java EE API的依赖关系设置为提供的范围,因为Web容器提供了这些类。 This scope is only available on the compilation and test classpath, and is not transitive. 该作用域仅在编译和测试类路径上可用,并且不可传递。

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

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