Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The attribute prefix fn does not correspond to any imported tag library

Tags:

java

jsp

jsf

tomcat

I try to run my jsp code on Tomcat v7 server but it failed.

org.apache.jasper.JasperException: /jsp/Checkout.jspx (line: 32, column: 51) The attribute prefix fn does not correspond to any imported tag library

But my jsp code had fn definition

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

My jsp code : 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>

How should I solve this problem?

I loaded the project again in eclipse, I just changed the code in web.xml.

servlet-mapping>
<servlet-name>ShopServlet</servlet-name>
<url-pattern>/ShopServlet</url-pattern>
</servlet-mapping> 

URL is : localhost:8080/eshopx/ShopServlet

The error message changed

description The requested resource is not available.

like image 488
rosemary Avatar asked Mar 14 '14 15:03

rosemary


1 Answers

You need to use the taglib declaration in your jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" 
    prefix="fn" %> 
like image 171
user3360944 Avatar answered Nov 03 '22 00:11

user3360944