记使用JSTL时的一次愚蠢错误
2013-05-08 11:52
211 查看
今天使用jstl的foreach,平时没问题,今天出现如下错误:
于是打开tomcat解析后的代码:
错误写法:
谨以此警告自己,不能再犯此低级错误!
javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.String javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193) javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170) javax.el.BeanELResolver.property(BeanELResolver.java:279)明明有id属性,类型为int型,且get,set都有,怎么会报错呢?
于是打开tomcat解析后的代码:
private boolean _jspx_meth_c_005fforEach_005f0(PageContext _jspx_page_context) throws Throwable { PageContext pageContext = _jspx_page_context; JspWriter out = _jspx_page_context.getOut(); // c:forEach org.apache.taglibs.standard.tag.rt.core.ForEachTag _jspx_th_c_005fforEach_005f0 = (org.apache.taglibs.standard.tag.rt.core.ForEachTag) _005fjspx_005ftagPool_005fc_005fforEach_0026_005fvar_005fitems.get(org.apache.taglibs.standard.tag.rt.core.ForEachTag.class); _jspx_th_c_005fforEach_005f0.setPageContext(_jspx_page_context); _jspx_th_c_005fforEach_005f0.setParent(null); // /WEB-INF/view/body.jsp(33,0) name = items type = java.lang.Object reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null _jspx_th_c_005fforEach_005f0.setItems(new String("notices")); // /WEB-INF/view/body.jsp(33,0) name = var type = java.lang.String reqTime = false required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null _jspx_th_c_005fforEach_005f0.setVar("notice"); int[] _jspx_push_body_count_c_005fforEach_005f0 = new int[] { 0 }; try { int _jspx_eval_c_005fforEach_005f0 = _jspx_th_c_005fforEach_005f0.doStartTag(); if (_jspx_eval_c_005fforEach_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) { do { out.write("\r\n"); out.write("<li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.request.contextPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false)); out.write("/news/detail?id="); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${notice.id}", java.lang.String.class, (PageContext)_jspx_page_context, null, false)); //注意,此时notice解析类型为String,不是bean,肯定有问题 out.write("\" title=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${notice.title}", java.lang.String.class, (PageContext)_jspx_page_context, null, false)); out.write("\"><font style=color:green>"); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${notice.title}", java.lang.String.class, (PageContext)_jspx_page_context, null, false)); out.write("</font></a></li>\r\n"); int evalDoAfterBody = _jspx_th_c_005fforEach_005f0.doAfterBody(); if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) break; } while (true); } if (_jspx_th_c_005fforEach_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { return true; } } catch (Throwable _jspx_exception) { while (_jspx_push_body_count_c_005fforEach_005f0[0]-- > 0) out = _jspx_page_context.popBody(); _jspx_th_c_005fforEach_005f0.doCatch(_jspx_exception); } finally { _jspx_th_c_005fforEach_005f0.doFinally(); _005fjspx_005ftagPool_005fc_005fforEach_0026_005fvar_005fitems.reuse(_jspx_th_c_005fforEach_005f0); } return false; }发现解析时notice变量被当做String了,不是Javabean对象,于是看代码,发现竟然少写了一个${}符号,stupid!!!
错误写法:
<c:forEach items="notices" var="notice"> <li><a href="${pageContext.request.contextPath}/news/detail/${notice.id}" title="${notice.title}"><font style=color:green>${notice.title}</font></a></li> </c:forEach>修正后:
<c:forEach items="${notices}" var="notice"> <li><a href="${pageContext.request.contextPath}/news/detail/${notice.id}" title="${notice.title}"><font style=color:green>${notice.title}</font></a></li> </c:forEach>
谨以此警告自己,不能再犯此低级错误!
相关文章推荐
- 解决通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048)的错误
- 一个愚蠢的错误,一次深刻的教训
- 错误整理(一)使用 JSTL 标签出现警告
- 在Windows7下配置Apache2.4服务器及错误解决方案-通常每个套接字地址(协议/网络地址/端口)只允许使用一次
- 错误信息:通常每个套接字地址(协议/网络地址/端口)只允许使用一次.
- 我的是CentOS6.3+MySQL5.1.57。重启了一次服务器后,使用 mysql -u root -p登陆是出现下面的错误: ERROR 2002 (HY000): Can't connect
- 解决使用adb命令提示“通常每个套接字地址(协议/网络地址/端口)只允许使用一次”错误
- #记一次fragment使用空指针错误NullPointerException
- 错误信息:通常每个套接字地址(协议/网络地址/端口)只允许使用一次.
- 记Struts2中使用JSTL tag lib 的错误
- 错误信息:通常每个套接字地址(协议/网络地址/端口)只允许使用一次.
- 在使用JSTL的时候不要把jsp文件命名为jstl.jsp,会提示错误
- 记一次使用utl_http方法调用接口,报字符或值错误
- Struts整合Spring时使用addFieldError出现一次错误提示后就一直有该提示
- 使用Byte的一次错误
- 解决apache开始时出现的“ (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次” 这个错误
- jsp页面中使用jstl的< c:choose> <c:when><c:otherwise>错误
- 一次jquery使用中的json错误
- 记一次使用Phoenix-Spark时的错误:bad symbolic reference. A signature in package.class refers to term
- SQL Server (MSSQLSERVER) 服务因 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 服务特定错误而停止。 解决方案!