今天在看JSTL一個測試程序
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<c:set var="userName" value="hellking"/>
<c:set value="19" var="age"/>
歡迎您,<c:out value="${userName}"/><hr>
<c:forEach var="i" begin="1" end="5">
<font size=${i}>${i}</font>
<br>
</c:forEach>
<c:if test="${age<18}">
對不起,你的年齡taida,不能訪問這個網頁◎!
</c:if>
<br>
</body>
</html>
的時候,發現放到JSTL的例子程序跟目錄下就可以正確顯示下面的結果
歡迎您,hellking
1
2
3
4
5
但是在自己設置的子目錄下就不能顯示正確的結果,變成下面的樣子
歡迎您,${userName}
${i}
${i}
${i}
${i}
${i}
找了很久發現是web.xml的配置問題,
原來子目錄的配置是這樣的,是從根目錄下拷過來的
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<display-name>JSTL Examples</display-name>
<description>
Examples for the 'standard' taglib (JSTL)
</description>
<listener>
<listener-class>org.apache.taglibs.standard.examples.startup.Init</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
后來發現把
<listener>
<listener-class>org.apache.taglibs.standard.examples.startup.Init</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
這些去掉就可以正常顯示,我用的服務器是TOMCAT5。5 有誰知道原因的解釋下啊??