Jsp jstl代码问题 .甚至{ 背景颜色:银色; } 注册页 用户名: 密码: 性别: 国家: 关于你: 社区: 名称 性别 国家 关于你 ${user.name} ${user.gender} ${user.country} ${user.aboutYou}

Jsp jstl代码问题 .甚至{ 背景颜色:银色; } 注册页 用户名: 密码: 性别: 国家: 关于你: 社区: 名称 性别 国家 关于你 ${user.name} ${user.gender} ${user.country} ${user.aboutYou},jsp,jstl,Jsp,Jstl,当我执行jsp页面时,这段代码根本不显示。完整的源代码如下 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.c

当我执行jsp页面时,这段代码根本不显示。完整的源代码如下

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
.even {
 background-color: silver;
}
</style>
<title>Registration Page</title>
</head>
<body>

<form:form action="add.htm" commandName="user">
 <table>
  <tr>
   <td>User Name :</td>
   <td><form:input path="name" /></td>
  </tr>
  <tr>
   <td>Password :</td>
   <td><form:password path="password" /></td>
  </tr>
  <tr>
   <td>Gender :</td>
   <td><form:radiobutton path="gender" value="M" label="M" /> <form:radiobutton
    path="gender" value="F" label="F" /></td>
  </tr>
  <tr>
   <td>Country :</td>
   <td><form:select path="country">
    <form:option value="0" label="Select" />
    <form:option value="India" label="India" />
    <form:option value="USA" label="USA" />
    <form:option value="UK" label="UK" />
   </form:select></td>
  </tr>
  <tr>
   <td>About you :</td>
   <td><form:textarea path="aboutYou" /></td>
  </tr>
  <tr>
   <td>Community :</td>
   <td><form:checkbox path="community" value="Spring"
    label="Spring" /> <form:checkbox path="community" value="Hibernate"
    label="Hibernate" /> <form:checkbox path="community" value="Struts"
    label="Struts" /></td>
  </tr>
  <tr>
   <td></td>
   <td><form:checkbox path="mailingList"
    label="Would you like to join our mailinglist?" /></td>
  </tr>
  <tr>
   <td colspan="2"><input type="submit" value="Register"></td>
  </tr>
 </table>
</form:form>
<c:if test="${fn:length(userList) > 0}">
 <table cellpadding="5">
  <tr class="even">
   <th>Name</th>
   <th>Gender</th>
   <th>Country</th>
   <th>About You</th>
  </tr>
  <c:forEach items="${userList}" var="user" varStatus="status">
   <tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">
    <td>${user.name}</td>
    <td>${user.gender}</td>
    <td>${user.country}</td>
    <td>${user.aboutYou}</td>
   </tr>
  </c:forEach>
 </table>
</c:if>
</body>
</html>

名称
性别
国家
关于你
${user.name}
${user.gender}
${user.country}
${user.aboutYou}

如果根本没有安装JSTL,就会发生这种情况。若要选中此选项,请右键单击webbrowser中的页面,然后选择“查看源”。如果您在所有HTML源代码中看到未解析的JSTL标记,那么这意味着它确实没有安装。然后,您需要将JSTL JAR放入
/WEB-INF/lib
文件夹中。对于Tomcat6.x或更高版本,只需将文件放在其中就足够了(并确保您的
web.xml
是按照Servlet2.5规范声明的)

但是如果您在HTML源代码中没有看到JSTL标记,那么这意味着条件
${fn:length(userList)>0}
总是
false
。您需要将非空的
userList
作为请求属性,以确保情况并非如此


顺便说一下,
${fn:length(userList)>0}
也可以简化为
${notempty userList}

我没有得到java.lang.NoSuchFieldError:DeferreExpression错误。然后您的类路径被多个不同版本的JSTL库污染。确保没有
jstl.jar
standard.jar
,而只有
jstl-1.2.jar
<c:if test="${fn:length(userList) > 0}">
    <table cellpadding="5">
        <tr class="even">
            <th>Name</th>
            <th>Gender</th>
            <th>Country</th>
            <th>About You</th>
        </tr>
        <c:forEach items="${userList}" var="user" varStatus="status">
            <tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">
                <td>${user.name}</td>
                <td>${user.gender}</td>
                <td>${user.country}</td>
                <td>${user.aboutYou}</td>
            </tr>
        </c:forEach>
    </table>
</c:if>