el表达式

来源:互联网 发布:删除关联表数据 编辑:程序博客网 时间:2024/05/29 17:03
调试了好久,el表达式死活无法在jsp中使用,自己也觉得奇怪。重新做了一个全新的工程问题依然存在。原来是servlet2.5搞的怪。依赖为:
  1. <dependency> 
  2.             <groupId>com.alibaba.external</groupId> 
  3.             <artifactId>java.servlet</artifactId> 
  4.             <version>2.5</version> 
  5.         </dependency> 

解决方案:在跳转到的页面(提交页则不用)添加<%@ page isELIgnored="false" %>

JSP中不能正常EL表达式
例如:入的是${true and true} EL表达 式,在面上示的的果并不是true而是${true and true}
原因是Servlet2.3或更低的版本 中没有定EL表达式,认为禁用EL表达式(JSP1.2也是禁用EL表达式)
解决方法:
JSP面中加入禁用EL表达式<%@ page isELIgnored="false" %>

Servlet2.4EL表达式(JSP2.0启用EL表达式)
如果不知道自己使用的版本是那个可以到web.xml中 去<web-app>
下面2.3版和2.4<web-app>

2.3
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "
http://java.sun.com/dtd/web-app_2_3.dtd">
2.4
<web-app http://java.sun.com/xml/ns/j2ee%22xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance">http://java.sun.com/xml/ns/j2ee"xmlns:http://www.w3.org/2001/XMLSchema-instance%22xsi:schemaLocation=%22http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLxsi:schemaLhttp://java.sun.com/xml/ns/j2ee">http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

【注意】

(1)取值的时候,一定是<%=request.getParameter("usercode") %>,而不是request.getAttribute("usercode")

(2)取得页面提交过来的内容:username:${param.username }

经过测试,在servlet2.3中只用使用${username}是可以的,但在2.5中不行;在action中添加如下java代码,通过${protocal }可以取得内容,可以用来传递隐含内容,类似于request.setAttribute("protocal")。

  1. private String protocal = "hello, the protocal."
  2. public String getProtocal() { 
  3.     return protocal; 
  1. username:<%=request.getParameter("username") %><br> 
  2.     username: ${username}<br> 
  3.     protocal: ${protocal } 

 (3)EL表达式 (详解)

http://blog.csdn.net/qwerasdf123/article/details/4189889

0 0