日期:2014-05-17  浏览次数:20807 次

EL表达式问题:当一个类继承ArrayList后,用EL取时就出错了??
很奇怪,反正继承ArrayList后,属性不能通过EL取到,
必须
TestEL myList = (TestEL)request.getAttribute("t");
String name = testEL.getName();
这样才能取到。

怎样才能以EL取到呢,求助???

代码:
Java code

package test;

import java.util.ArrayList;


public class TestEL extends ArrayList {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
}


jsp页面:
HTML code

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="test.*"%>
<%
TestEL t = new TestEL();
t.setName("testxxxxxxxxxx");
request.setAttribute("t", t);
%>
${t.name}<br/>



异常:
java.lang.NumberFormatException: For input string: "name"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at javax.el.ListELResolver.coerce(ListELResolver.java:167)
at javax.el.ListELResolver.getValue(ListELResolver.java:51)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
2011-12-12 15:26:13 org.apache.catalina.core.StandardWrapperValve invoke


------解决方案--------------------
java.lang.NumberFormatException: For input string: "name"
是不是什么地方把t.name当数字用了,检查一下是否还有其他地方在用name。
------解决方案---------------