empty/not empty EL表达式使用注意

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /main/index.jsp(79,6) "${not empty(LOGINNAME_OA)&&not empty(LOGINPWD_OA)&&not empty(ISCHECK_OA)&&not empty(OAIP)}" contains invalid expression(s): javax.el.ELException: Function ':empty' not found
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
	org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1151)
	org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
	org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
	org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
	org.apache.jasper.compiler.Validator.validate(Validator.java:1739)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.philisense.base.MessageFilter.doFilter(MessageFilter.java:26)
	org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
	org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
	com.philisense.base.AuthenticationFilter.doFilter(AuthenticationFilter.java:105)
	com.philisense.base.MessageFilter.doFilter(MessageFilter.java:26)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


今天在用EL表达式时发现empty不太好使出现如上的错误,但在同样的代码在他人机器好使,于是查了一下发现反应此问题还挺多的,有许多人反映跟jdk和tomcat的版本相关,无意间在网上发现了这篇贴子的回帖解决了此问题(将not empty(xx)改为not empty  (xx),即是在empty与()之间加上空格,具体看帖子的绿色字体的回帖解释),在此分享一下:

链接地址:http://jira.codehaus.org/browse/MRM-905



Details

  • Type:Bug Bug
  • Status:Closed Closed
  • Priority:Blocker Blocker
  • Resolution:Fixed
  • Affects Version/s:1.1
  • Fix Version/s:1.1.2
  • Component/s:Web Interface
  • Labels:
    None
  • Environment:
    Windows XP SP3 FR
    java (JDK) "1.6.0_07"
    apache tomcat "6.0.18"
    activation-1.1.jar
    mail-1.4.jar
    derby-10.1.3.1.jar
  • Number of attachments :
    3

Description

  After installing as Wiki said, as a tomcat WAR, i get parsing error in some JSP/TAG code.

  Some examples :

  org.apache.jasper.JasperException: /WEB-INF/jsp/components/companyLogo.jsp(22,0) "${!empty(organisationLogo)}" contient          d'incorrecte(s) expression(s): javax.el.ELException: Function ':empty' not found
  org.apache.jasper.JasperException: /WEB-INF/tags/currentWWUrl.tag(29,0) "${!empty(action) && !empty(namespace)}" contient       d'incorrecte(s) expression(s): javax.el.ELException: Function ':empty' not found

  I've added logs as attachments.

  The workaround is very simple : 
  replace EL exepressions containing "empty(" with "empty (", and "not(" with "not (" as EL expression requires.

  This is a VERY strange error since i've successufully setup Archiva on my profesionnal server, and i got these error on two distinct personnal   systems.

  I'll check the professionnal/personnal system differences.

Attachments

  1. Text File
    catalina.2008-08-10.log
    10/Aug/08 1:06 PM
    73 kB
  2. Text File
    localhost.2008-08-10.log
    10/Aug/08 1:06 PM
    10 kB
  3. Text File
    MRM-905.patch
    15/Aug/08 5:08 AM
    19 kB

Activity

Maria Odea Ching added a comment - 14/Aug/08 1:07 AM - edited

  I couldn't replicate this on trunk (-r685734), with the following environment:

  • ubuntu linux
  • java version "1.5.0_11"
  • tomcat 6.0.14
  • activation-1.1.jar, derby-10.1.3.1.jar and mail-1.4.jar
Maria Odea Ching added a comment - 14/Aug/08 4:39 AM

  I was now able to replicate this issue when I deployed Archiva to Tomcat 6.0.18. I don't see the error in 5.5.17 and 6.0.14 though.. there must be a conflict with the EL lib included in      6.0.18. I'll try your suggestion above to fix this, thanks! 

Fabrice Daugan added a comment - 14/Aug/08 6:35 AM

  Yes! 
  that's what i just found during the professionnal/personnal system differences.
  Same JDK, but 6.0.14 Tomcat version.

Roman Legat added a comment - 14/Aug/08 10:08 AM - edited

  Same here.
  My configuration:
  Ubuntu Server 8.04
  java 1.6.0_06
  tomcat 6.0.18
  Archiva 1.1.1 deployed as a .war

  Stacktrace starts with: 
  org.apache.jasper.JasperException: /WEB-INF/jsp/admin/repositories.jsp(53,0) "${empty(managedRepositories)}" contains invalid expression(s): javax.el.ELException: Function ':empty'    not found
  org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)

  The suggested fix works for me. Fabrice, you made my day!
  I ran 
  sudo sed -i.BAK -e "s/empty(/empty (/g" *.jsp*
  sudo sed -i.BAK -e "s/not(/not (/g" *.jsp*
  over the jsp folder and it works like a charm.

  So the question is, is "empty(" invalid or not. There have been quite some changes in jasper between
  6.0.14 and 6.0.18 (http://tomcat.apache.org/tomcat-6.0-doc/changelog.html), but i'm really not into the jsp stuff, so I couldn't tell...

Fabrice Daugan added a comment - 14/Aug/08 12:59 PM - edited

  Also, i think there are some common code with Continuum, since the same error (but non blocker) occurs in the header.

  As said in the EL specification (simplified version)

  http://java.sun.com/products/jsp/syntax/2.0/syntaxref207.html

  ${ Expression }
  Expression = {(UnaryOp Expression) | Value }
  UnaryOp = {'-' | ! | not | empty }
  Value = {ValuePrefix | (Value ValueSuffix) }
  ValuePrefix = {Literal | '('Expression')' | ImplicitObject | Java language identifier}
  ValueSuffix = { . Identifier | '['Expression']'}
  Literal = {StringLiteral | null}
  StringLiteral = {'[^(' | \) | \' | \\]+' | "[^(" | \) | \" | \\]+"}

  If we read well the Tomcat error is right : since the grammar does not validate :
  empty("hello")
  but validate :
  empty ("hello")

Maria Odea Ching added a comment - 14/Aug/08 8:20 PM - edited

  Ok, thanks a lot for both of your help on this! Would either of you like or is interested to submit a patch for the fix? 

Fabrice Daugan added a comment - 15/Aug/08 5:08 AM

  The patch did from the revision 686186.
  The root path of this patch is http://svn.apache.org/repos/asf/archiva/trunk/archiva-modules/archiva-web/archiva-webapp

Maria Odea Ching added a comment - 17/Aug/08 8:46 PM

  Thanks for the patch Fabrice! I already applied it in trunk -r686665 and tested it with Tomcat versions 5.5.17, 6.0.14 and 6.0.18. It works nicely 

 


 

原文地址:https://www.cnblogs.com/jice/p/2319196.html