title: javax.el.ELException: Cannot convert [light, amber, brown, dark] of type class java.util.ArrayList to class [Ljava.lang.String;
body: <p>I am practicing the examples in Head First Servlets and JSP book.</p>
  
  <p>I am trying to create a simple tag which acts like <code>html select</code> tag. I have created the tld, tag handler and the rest of the servlets as well as the JSPs according to the examples given in the book. For reference please see page numebr 542.</p>
  
  <p>But, I am getting the above said exception. Any help will be greatly appreciated. </p>
  
  <blockquote>
    <p><strong>TLD:</strong></p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;!DOCTYPE taglib
          PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
          "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd"&gt;
  &lt;taglib&gt;
      &lt;tlib-version&gt;1.2&lt;/tlib-version&gt;
      &lt;jsp-version&gt;1.2&lt;/jsp-version&gt;
      &lt;short-name&gt;Forms Taglib&lt;/short-name&gt;
      &lt;uri&gt;http://example.com/tags/forms&lt;/uri&gt;
      &lt;description&gt;
          An example tab library of replacements for the HTML form tags.
      &lt;/description&gt;
      &lt;tag&gt;
          &lt;name&gt;select&lt;/name&gt;
          &lt;tag-class&gt;com.jstl.select.SelectTagHandler&lt;/tag-class&gt;
          &lt;body-content&gt;empty&lt;/body-content&gt;
          &lt;attribute&gt;
              &lt;name&gt;optionList&lt;/name&gt;
              &lt;required&gt;true&lt;/required&gt;
              &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
              &lt;type&gt;java.util.List&lt;/type&gt;
          &lt;/attribute&gt;
          &lt;attribute&gt;
              &lt;name&gt;name&lt;/name&gt;
              &lt;required&gt;true&lt;/required&gt;
          &lt;/attribute&gt;
          &lt;attribute&gt;
              &lt;name&gt;size&lt;/name&gt;
              &lt;required&gt;true&lt;/required&gt;
          &lt;/attribute&gt;
      &lt;/tag&gt;
  &lt;/taglib&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>ColorServlet- Invoked first:</strong></p>
  </blockquote>
  
  <pre><code>public class ColorServlet extends HttpServlet {
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          List colorList = new ArrayList();
  
          colorList.add("light");
          colorList.add("amber");
          colorList.add("brown");
          colorList.add("dark");
  
          getServletContext().setAttribute("colorList", colorList);
          RequestDispatcher view = request.getRequestDispatcher("select-beer.jsp");
          view.forward(request, response);
  
      }
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request, response);
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>The jsp(select-beer.jsp);</strong></p>
  </blockquote>
  
  <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  &lt;%@ taglib prefix="my" uri="http://example.com/tags/forms" %&gt;
  
  &lt;form action="select.do" method="POST"&gt;
      &lt;p&gt;Select Beer Characteristics: &lt;/p&gt;
      Color:
      &lt;my:select optionList="${applicationScope.colorList}" name="color" size="1"/&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;input type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>The TagHandler class:</strong></p>
  </blockquote>
  
  <pre><code>public class SelectTagHandler extends SimpleTagSupport {
      private String name;
      private String size;
      private List optionList;
  
      private static final String ATTR_TEMPLATE = "%s='%s'";
      private static final String OPTION_TEMPLATE = "&lt;option value='1$s'&gt;%1$s&lt;/option&gt;";
  
      public void setName(String name) {
          this.name = name;
      }
  
      public void setSize(String size) {
          this.size = size;
      }
  
      public void setOptionList(List optionList) {
          this.optionList = optionList;
      }
  
      @Override
      public void doTag() throws JspException, IOException {
          JspWriter out = getJspContext().getOut();
          out.print("&lt;select ");
          out.print(String.format(ATTR_TEMPLATE, "name", this.name));
          out.print(String.format(ATTR_TEMPLATE, "size", this.size));
          out.println('&gt;');
  
          for (Object option : this.optionList) {
              String optionTag = String.format(OPTION_TEMPLATE, option.toString());
              out.println(optionTag);
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>StackTrace</strong></p>
  </blockquote>
  
  <pre><code>20:41:53,383 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jee_war_exploded].[jsp]] (http--127.0.0.1-8000-1) Servlet.service() for servlet jsp threw exception: javax.el.ELException: Cannot convert [light, amber, brown, dark] of type class java.util.ArrayList to class [Ljava.lang.String;
      at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420) [jbossweb-7.0.13.Final.jar:]
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:191) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jsp.select_002dbeer_jsp._jspx_meth_my_005fselect_005f0(select_002dbeer_jsp.java:96)
      at org.apache.jsp.select_002dbeer_jsp._jspService(select_002dbeer_jsp.java:68)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
      at com.jstl.select.ColorServlet.doPost(ColorServlet.java:26) [classes:]
      at com.jstl.select.ColorServlet.doGet(ColorServlet.java:31) [classes:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
      at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
  
  20:41:53,391 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jee_war_exploded].[ColorServlet]] (http--127.0.0.1-8000-1) Servlet.service() for servlet ColorServlet threw exception: javax.el.ELException: Cannot convert [light, amber, brown, dark] of type class java.util.ArrayList to class [Ljava.lang.String;
      at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420) [jbossweb-7.0.13.Final.jar:]
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:191) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jsp.select_002dbeer_jsp._jspx_meth_my_005fselect_005f0(select_002dbeer_jsp.java:96)
      at org.apache.jsp.select_002dbeer_jsp._jspService(select_002dbeer_jsp.java:68)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
      at com.jstl.select.ColorServlet.doPost(ColorServlet.java:26) [classes:]
      at com.jstl.select.ColorServlet.doGet(ColorServlet.java:31) [classes:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
      at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
  </code></pre>