Java IntelliJ 和 JSP/JSTL 无法在 tomcat7 中为 JSTL 解析 taglib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31043869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ and JSP/JSTL cannot resolve taglib for JSTL in tomcat7
提问by dsadnick
First of all my JSTl code works on my server because i have the proper Jar file in the Lib folder in tomcat7. This is just really an IDEA problem. My questions comes down to where i put the same jar file in my file directory within IntelliJ.
首先,我的 JSTl 代码可以在我的服务器上运行,因为我在 tomcat7 的 Lib 文件夹中有正确的 Jar 文件。这只是一个真正的 IDEA 问题。我的问题归结为我在 IntelliJ 中的文件目录中放置相同 jar 文件的位置。
I have ran into a error in IntelliJ and JSTL.
我在 IntelliJ 和 JSTL 中遇到了错误。
My problem is that when i use
我的问题是当我使用
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
It results in Cannot resolve taglib with uri. I have tried different Jar files and I do know that i have to correct version for my servlet.
它导致无法使用 uri 解析 taglib。我尝试了不同的 Jar 文件,我知道我必须为我的 servlet 更正版本。
Im running tomcat7 on Ubuntu Server 15.04, and IntelliJ 14.1.3.
我在 Ubuntu Server 15.04 和 IntelliJ 14.1.3 上运行 tomcat7。
I have tried importing the jar file though the Project Structure, and including it in various places but still the same error after re-building the project, and closing down and reopening the IDEA.
我尝试通过项目结构导入 jar 文件,并将其包含在各个位置,但在重新构建项目并关闭并重新打开 IDEA 后仍然出现相同的错误。
This sample code runs when deployed to tomcat but IntelliJ keeps giving errors.
此示例代码在部署到 tomcat 时运行,但 IntelliJ 不断给出错误。
<table border="1">
<c:forEach var="a" items="${data}">
<tr>
<td>${a}</td>
</tr>
</c:forEach>
</table>
<c:forEach begin="0" end="255" var="i">
<span style='color:rgb(
<c:out value="${i}"/>,
<c:out value="${i}"/>,
<c:out value="${i}"/>);'>
<c:out value="${i}"/></span> <br />
</c:forEach>
I would like to know how to stop IntelliJ from giving errors on my Syntax even though the code works.
我想知道如何阻止 IntelliJ 在我的语法上给出错误,即使代码有效。
I have read JSTL in IntelliJ gives errors in JSP
我读过IntelliJ 中的 JSTL 在 JSP 中给出错误
and
和
https://www.jetbrains.com/idea/features/jsp_editor.html
https://www.jetbrains.com/idea/features/jsp_editor.html
Still no luck.
仍然没有运气。
采纳答案by Shams Ul Azeem
First add this to the top of your .jsp
file:
首先将其添加到.jsp
文件的顶部:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
It will still give syntax error but you can fix that by adding javax.servlet:jstl:1.2
as a module dependency. To do that, follow these steps:
它仍然会出现语法错误,但您可以通过添加javax.servlet:jstl:1.2
为模块依赖项来解决该问题。为此,请按照以下步骤操作:
- Click your project name and press F4to bring up the module settings dialog.
- Then go to the
dependencies
tab in themodules
section. - Click the green
+
icon --> library --> From Maven. - Search for
javax.servlet:jstl:1.2
in the search bar and press OK and it will download and add the above mentioned library as a module. - Now you should not have any kind of syntax error.
- 单击您的项目名称,然后按F4以调出模块设置对话框。
- 然后转到
dependencies
该modules
部分中的选项卡。 - 单击绿色
+
图标 --> 库 --> 从 Maven。 - 搜索
javax.servlet:jstl:1.2
在搜索栏中,然后按确定,它会下载并添加上述库作为一个模块。 - 现在你不应该有任何语法错误。
回答by Sineth Lakshitha
If you are using maven, add following code in pom.xml inside the <dependencies></dependencies>
tag
如果您使用的是 maven,请在 pom.xml<dependencies></dependencies>
标签内添加以下代码
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
回答by Hyman J
If you are still getting errors after following the instructions provided by Shams UI Azeem, you may need to add the JSTL library to the WAR Exploded artifact. To do this:
如果按照 Shams UI Azeem 提供的说明操作后仍然出现错误,则可能需要将 JSTL 库添加到 WAR Exploded 工件中。去做这个:
- Go to Project Structure. Under Project Settings, select Artifacts. On the bottom of the menu box, there may be a message which mentions that the JSTL library used is not included in the WAR.
- 转到项目结构。在项目设置下,选择工件。在菜单框的底部,可能会出现一条消息,指出所使用的 JSTL 库未包含在 WAR 中。
2a. Message visible.If the message is displayed, there should be a Fix button next to it. Click this Fix button. Select "add javax.servlet:jstl:1.2
to the artifact".
2a. 消息可见。如果显示该消息,则其旁边应该有一个修复按钮。单击此修复按钮。选择“添加javax.servlet:jstl:1.2
到工件”。
2b. Message not visible.If the message is not displayed, then look above to see if the javax.servet:jstl:1.2 (Project Library)
is underneath the Available Elements column. If it is, right click it and select "Put into /WEB-INF/lib".
2b. 消息不可见。如果未显示该消息,请查看上方以查看 是否javax.servet:jstl:1.2 (Project Library)
在可用元素列下方。如果是,请右键单击它并选择“放入/WEB-INF/lib”。
If you are working with Maven, the Fix message will not appear, though you will still need to do this.
如果您正在使用 Maven,则不会出现修复消息,但您仍然需要这样做。
回答by Ravendra Singh
Add below dependency to your pom.xml
将以下依赖项添加到您的 pom.xml
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>