web.xml中"web-app_2_5.xsd"引起的EL表达式无效异常

web.xml中"web-app_2_5.xsd"引起的EL表达式无效异常

org.apache.jasper.JasperException: Unable to convert string "${tasks}" to class "java.util.Collection" for attribute "items": Property Editor not registered with the PropertyEditorManager
这种异常,试着调了不少时间,tasks是从后台传过来的list集,在前台jsp页面不能使用${tasks},弄的我莫名其妙怎么会出现这样的问题,其实从后台取值并传值到前台来根本就没有错,而前台JSP页面EL表达式无效,解析不到EL表达式,引起的原因是web.xml中:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
注意里面的web-app_2_5.xsd,就是这个引起的,在web-app_2_4.xsd中就不会出现这种问题(这个版本的isELIgnored默认设置为false)。
在不改变web.xml2.5版本的情况下解决办法是:在jsp页面头加:<%@page isELIgnored="false"%>   问题得以解决。
 
自定义标签
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
< %@page import="com.cn.tag.Person"%>
<%@ taglib uri="/mytag" prefix="hello" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <%
   List<Person> persons = new ArrayList<Person>();
   Person p1  = new Person("caodaoxi",25," [email protected]");
   Person p2  = new Person("caodaoxi",25," [email protected]");
   Person p3  = new Person("caodaoxi",25," [email protected]");
   Person p4  = new Person("caodaoxi",25," [email protected]");
   Person p5  = new Person("caodaoxi",25," [email protected]");
   persons.add(p1);
   persons.add(p2);
   persons.add(p3);
   persons.add(p4);
   persons.add(p5);
  %>
  <hello:tb ps="<%=persons%>"/>
  </body>
</html>
hello.tld
 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                        " http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
 <tlib-version>1.0</tlib-version>
 <jsp-version>1.2</jsp-version>
 <short-name>hello</short-name>
 <tag>
  <name>hello</name>
  <tag-class>com.cn.tag.Hello</tag-class>
  <body-content>empty</body-content>
  <attribute>
   <name>color</name>
   <required>true</required>
  </attribute>
  <attribute>
   <name>backgroundImage</name>
   <required>false</required>
  </attribute>
 </tag>
 <tag>
  <name>tb</name>
  <tag-class>com.cn.tag.TagDemo1</tag-class>
  <body-content>empty</body-content>
  <attribute>
   <name>ps</name>
   <required>false</required>
   <rtexprvalue>true</rtexprvalue>
   <type>java.util.List</type>
  </attribute>
 </tag>
</taglib>

TagDemo1.java
package com.cn.tag;
import java.io.IOException;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/*
 *项目名称:tag
 *类名: TagDemo1.java
 *作者: 曹道喜
 *创建日期: Oct 17, 2011  11:52:56 AM
 *类说明:
 */
public class TagDemo1 extends TagSupport {
 
 private List<Person> ps = null;
 public List<Person> getPs() {
  return ps;
 }
 public void setPs(List<Person> ps) {
  this.ps = ps;
 }
 @Override
 public int doStartTag() throws JspException {
  // TODO Auto-generated method stub
  JspWriter out = pageContext.getOut();
  StringBuffer buffer = new StringBuffer();
  System.out.print("-------------");
  try {
   buffer.append("<table>" +
       "<tr>" +
        "<th>姓名</th>" +
        "<th>年龄</th>" +
        "<th>邮箱</th>" +
       "</tr>"
       );
   System.out.print(buffer.toString());
   if(ps!=null&&ps.size()!=0){
    for(Person person:ps){
     buffer.append("<tr>" +
         "<td>"+person.getName()+"</td>" +
         "<td>"+person.getAge()+"</td>" +
         "<td>"+person.getEmail()+"</td>" +
          "</tr>"
         );
    }
   }else{
    buffer.append("<td>没有想要的数据</td>");
   }
   buffer.append("</table>");
   out.write(buffer.toString());
   out.flush();
   out.close();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return TagSupport.SKIP_BODY;
 }
 @Override
 public int doEndTag() throws JspException {
  // TODO Auto-generated method stub
  return super.doEndTag();
 }
 @Override
 public int doAfterBody() throws JspException {
  // TODO Auto-generated method stub
  return super.doAfterBody();
 }
}

你可能感兴趣的:(web.xml)