您的位置:首页 > Web前端 > JavaScript

JSP 2.1-2.5上用JSTL和EL(表达式语言)的问题

2008-05-16 19:03 423 查看
Preface

在浏览本文之前,请你保证正在使用的是JSP 2.1以上Version,JSP页面上使用到JSTL和EL(表达式语言)。

Introduction

本文主要讲述在JSP 2.1以上Version中使用JSTL时遇到的EL(表达式)问题。

Content

Step 1 - Problem Description

我们通常根据一些书本或者教程的例子去做时往往会出现一些问题,那是因为Java的各种技术在不断更新换代,不少function在不同version上会出现差别或者问题。以下讲述的就是因这样而产生的一个问题。

以我用的JSP 2.5 version来说,以下是一个新创建的JSP页面并且加上了JSTL写的两句语句以用来测试:

<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/core" prefix="c"%>

<c:set var="userName" value="ABC"/>
<c:set var="userName2" value="${userName}"/>

<html:html lang="true">
<head>
<html:base />

<title>ELTest.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
This a struts page. <br>
</body>
</html:html>

以上这段代码在我的JSP 2.1 - 2.5 中会产生如下错误信息:

According to TLD or attribute directive in tag file, attribute value does not accept any expressions

Step 2 - Reason

原因很简单,因为这条JSTL的URI在JSP 2.1 Version后已经不适用了。

Step 3 - Solution

解决的办法有几种,我只挑最实际最标准的一种就是更改URI的Link,如下:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

(注意:增加了jsp一层)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: