我是JSP新手并使用Expression语言.我正在使用Eclipse Galileo 2.5版和Tomcat 6服务器.我只是想问一下,我的简单表达式语言不会像我写的那样打印${1>2},假设它给出了假,但${1>2}它只在呈现页面时显示 .但是当我使用<c:out value="${1>2}"/>它时,正确打印错误.我认为标签库存在问题.请建议我这样做的原因我给出了一个示例代码,以便您可以了解我的错误: -
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Expression Language Example</title>
</head>
<body>
Is 1 greater than 2 using cout :<c:out value="${1>2}"/>
Is 1 greater than 2 without using cout: ${1>2}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
根据答案更新,这里有更多信息:
我正在展示我的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/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ScriptLessJsp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>ElServlet</display-name>
<servlet-name>ElServlet</servlet-name>
<servlet-class>com.servlet.El.ElServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ElServlet</servlet-name>
<url-pattern>/ElServlet</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>Collections</display-name>
<servlet-name>Collections</servlet-name>
<servlet-class>com.servlet.El.Collections</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Collections</servlet-name>
<url-pattern>/go</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
在我的lib文件夹中,我只添加了jstl.jar以便我可以使用<c:out>标签来显示,但我的EL模板文本不起作用.
Bal*_*usC 53
我引用了我之前提供的答案,解决了EL不工作的问题:
换句话说,EL表达式没有被评估?这可能有以下一个或多个原因:
- 有问题的应用程序服务器不支持JSP 2.0.
- 在
web.xml未声明为的Servlet 2.4或更高版本.- 该
@page配置有isELIgnored=true.- web.xml配置为
<el-ignored>true</el-ignored>in<jsp-config>.
在您的特定情况下,EL在taglib中工作,但不在模板文本中,因此我怀疑它是由第2点引起的.确保您web.xml的声明至少为 Servlet 2.4.由于Tomcat 6.0支持Servlet 2.5,我建议您将其声明web.xml为Servlet 2.5:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="Your_WebApp_ID"
version="2.5">
<!-- Here you go. -->
</web-app>
Run Code Online (Sandbox Code Playgroud)
我在此看到的另一个罕见原因是在类路径中与EL JAR发生冲突.确保您没有将任何特定于应用程序服务器的JAR文件复制到您的webapp中,WEB-INF/lib或者更糟糕的是,JRE/lib.
由于您已经在使用Eclipse和Tomcat,我将查看您用于此目的的开发步骤.确保您正在使用"Eclipse for Java EE开发人员",并且已经在Eclipse的Servers视图中集成了Tomcat实例,并且您已经创建了一个动态Web项目设置为"Servlet 2.5",它使用了Tomcat实例.这样一切都应该自动化(Eclipse将在构建路径本身中使用appserver的库并自动生成符合Servlet 2.5的版本web.xml).
更新:根据您的更新:这些com.servlet.Elservlet看起来很可疑.他们究竟做了什么?解析EL?删除它们并重试.
Ily*_*iev 13
设置<%@ page isELIgnored ="false"%>对我有帮助.在我的案例中,不知道为什么它是问题的根源.还不清楚为什么呢
Jim*_*mmy 11
在我的例子中,我使用maven archetype生成器生成了一个webapp,我使用了maven-archetype-webapp.我需要改变两件事:
在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/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
Run Code Online (Sandbox Code Playgroud)默认情况下,eclipse生成带头的jsp文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Run Code Online (Sandbox Code Playgroud)只需删除它.
| 归档时间: |
|
| 查看次数: |
61713 次 |
| 最近记录: |