本文介绍了jstl< c:if>标签在jsp文件中不起作用,在tomcat 7中出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsp文件中使用jstl标记<c:if>时遇到问题.基本上,尽管它们是相关的,但我应该将其作为两个问题.

I have problem using jstl tag <c:if> in jsp file. Basically I should make this as 2 questions although they are related.

在我的WEB-INF/lib中,我放了一个jstl 1.2.jar

In my WEB-INF/lib, I put a jstl 1.2.jar

在我的jsp文件中,放置了这个<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>.

In my jsp file, I put this <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>.

在我的jsp文件中,我使用<c:if>做某事.如果条件为真,则会显示一些特殊消息

In my jsp file, I use the <c:if> to do something. If the condition is true, it will shows some special message

<c:if>内的内容基本上不起作用,因为即使条件为true也不显示该消息.

Basically the contents inside <c:if> is not working, because the message is not shown even the condition is true.

但是,如果我更改为使用旧的命名空间,则为<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>.其他变量未更改,则if标记起作用,因为显示了if标记内的消息.

But if I changed to use the older namespace, <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>. Others are not changed, then the if tag is working, because the message inside the if tag is shown.

我的第一个问题是为什么我必须在命名空间中使用/jstl而不是/jsp/jstl.我正在使用jstl1.2.jar.因此,我应该使用1.2版的新版uri.但是,较旧的uri可以使用,但不适用于较新的用户.

My first question is why I have to use /jstl instead of /jsp/jstl in namespace. I am using jstl1.2.jar. so I am supposed to use the newer uri for 1.2. however, older uri works but not newer uir.

我忽略了我遇到的第一个问题,只是将/jstl用作我的命名空间,只是因为它使我的Web应用程序按我想要的方式工作.但是,当我将Web应用程序部署到tomcat 7.X中时,它将显示以下异常:

I ignore the first question I have, and just use /jstl as my namespace just because it makes my web app work the way I want. However, when I deploy my web app into tomcat 7.X, it shows exceptions as the following:

/mywebapp.jsp行:35,列:10,即< c:if>标记.

in /mywebapp.jsp line:35, column:10, that is < c:if> tag.

如果我将名称空间从<%@ taglib prefix ="c" uri ="http://java.sun.com/jstl/core"%>更改为<%@ taglib prefix ="c" uri ="http://java.sun.com/jsp/jstl/core"%>,它可以成功部署在tomcat中,但< c:if>标签没有用.但是,<c:if>标记之外的其他代码也可以工作.

If I change the namespace from <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> to <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>, it can deploy in tomcat successfully but the functionality inside of < c:if> tag is not useful. other codes outside of <c:if> tag work though.

所以我很困惑,真的想知道如何解决这个问题.

So I am very confused and really want to know how to fix this.

顺便说一句,我正在使用servlet 2.5,jsp 2.0,jstl 1.2.我确实尝试将jsp2.0升级到jsp2.1,以查看是否可以解决第一个问题,但是我不知道如何升级jsp版本.

By the way, I am using servlet 2.5, jsp 2.0, jstl 1.2. I did try to upgrade the jsp2.0 to jsp2.1 in order to see if I can fix the first problem, but I have no idea how to upgrade jsp version.

推荐答案

如果/WEB-INF/lib中具有JSTL 1.0的standard.jar,则可能会发生这种情况.摆脱它.另请参见我们的JSTL Wiki页面.顺便说一句,我假设您没有接触过Tomcat和JRE自己的/lib文件夹,并且没有在其中放置任何与JSTL相关的JAR,或者没有认真地尝试解决问题就提取了JSTL JAR的内容.

That can happen if you have a standard.jar of JSTL 1.0 in the /WEB-INF/lib. Get rid of it. See also our JSTL wiki page. I by the way assume that you've untouched Tomcat's and JRE's own /lib folders and have not dropped any JSTL-related JARs in there, or have extracted the JSTL JAR's contents in a careless attempt to solve the problem.

您绝对不应该自己在/WEB-INF/lib中提供任何Servlet或JSP库. Servlet容器(在您的情况下为Tomcat)已经附带了它.另请参见如何操作我可以在Eclipse项目中导入javax.servlet API吗?

You should absolutely not provide any Servlet or JSP libraries in /WEB-INF/lib yourself. The servlet container (in your case, Tomcat) already ships with it. See also How do I import the javax.servlet API in my Eclipse project?

您只需要确保web.xml根声明符合servlet容器支持的内容即可. Tomcat 7是与Servlet 3.0兼容的容器,因此您的web.xml根声明应如下所示:

You only need to make sure that your web.xml root declaration complies whatever your servlet container supports. Tomcat 7 is a Servlet 3.0 compatible container, so your web.xml root declaration should look like this:

<?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">

    <!-- Config here. -->

</web-app>

这篇关于jstl&lt; c:if&gt;标签在jsp文件中不起作用,在tomcat 7中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:44