我尝试在Tomcat v7服务器上运行我的jsp代码,但是失败了。
org.apache.jasper。JasperException:/jsp/结帐。属性前缀fn不对应于任何导入的标签库
但是我的jsp代码有fn定义
xmlns: fn = " http://java.sun.com/jsp/jstl/functions "
我的jsp代码:Checkout.jspx
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:eshop="urn:jsptld:/WEB-INF/tlds/eshop.tld"
version="2.1"
>
<jsp:directive.page
language="java"
contentType="application/xhtml+xml;charset=UTF-8"
/>
<jsp:output omit-xml-declaration="false"/>
<jsp:output
doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>
<c:url var="cssUrl" value="/css/eshop.jspx"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check Out</title>
<link rel="stylesheet" href="${cssUrl}" type="text/css"/>
</head>
<body>
<jsp:include page="TopMenu.jspx" flush="true"/>
<jsp:include page="LeftMenu.jspx" flush="true"/>
<div class="content">
<h2>CheckOut</h2>
<c:choose>
<c:when test="${fn:length(shoppingCart) > 0}">
<form action="">
<input type="hidden" name="action" value="orderConfirmation"/>
<table class="checkout">
<tr>
<th colspan="2">Delivery Details</th>
</tr>
<tr>
<td>Contact Name:</td>
<td><input type="text" name="contactName"/></td>
</tr>
<tr>
<td>Delivery Address:</td>
<td><input type="text" name="deliveryAddress"/></td>
</tr>
<tr>
<th colspan="2">Credit Card Details</th>
</tr>
<tr>
<td>Name on Credit Card:</td>
<td><input type="text" name="ccName"/></td>
</tr>
<tr>
<td>Credit Card Number:</td>
<td><input type="text" name="ccNumber"/></td>
</tr>
<tr>
<td>Credit Card Expiry Date:</td>
<td><input type="text" name="ccExpiryDate"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Confirm Order"/></td>
</tr>
</table>
</form>
</c:when>
<c:otherwise>
<p class="error">ERROR: You can't check out an empty shopping cart!</p>
</c:otherwise>
</c:choose>
</div>
</body>
</html>
</jsp:root>
web . xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee;http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>eshop</display-name>
<servlet>
<description>
</description>
<display-name>ShopServlet</display-name>
<servlet-name>ShopServlet</servlet-name>
<servlet-class>eshop.ShopServlet</servlet-class>
<init-param>
<param-name>base</param-name>
<param-value>/shop</param-value>
</init-param>
<init-param>
<param-name>imageURL</param-name>
<param-value>/images/</param-value>
</init-param>
<init-param>
<param-name>jdbcDriver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</init-param>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:mysql://localhost:3306/shop</param-value>
</init-param>
<init-param>
<param-name>dbUserName</param-name>
<param-value>root</param-value>
</init-param>
<init-param>
<param-name>dbPassword</param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ShopServlet</servlet-name>
<url-pattern>/shop/*</url-pattern>
</servlet-mapping>
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>
我该如何解决这个问题?
我在eclipse中重新加载项目,我只是更改了web.xml中的代码。
servlet-mapping>
<servlet-name>ShopServlet</servlet-name>
<url-pattern>/ShopServlet</url-pattern>
</servlet-mapping>
URL为:localhost:8080/eshopx/ShopServlet
错误信息更改
description请求的资源不可用。
您需要在jsp
中使用标签库声明<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn" %>