java.lang.NoSuchMethodException:java.lang.String.substring(java.lang.Long,java.lang.Long)

时间:2012-05-11 19:11:43

标签: java eclipse spring jsp tomcat

我在其中一台机器上运行了jsp代码。但是,当我复制到另一台机器时,我得到的是没有这样的方法发现异常。我是新来的春天。有人可以解释我错过了什么。

以下是导致异常的代码行:

<c:set var="rawDate" value="${result.getDate()}"/>
<c:set var="rawTime" value="${result.getTime()}"/>
<td id="formattedDate" class="center"><c:out value="${rawDate.substring(4,6)}"/>/<c:out value="${rawDate.substring(6,8)}"/></td>
<td id="formattedTime" class="center"><c:out value="${result.getTime().substring(0,2)}"/>:<c:out value="${result.getTime().substring(2,4)}"/></td>

这是堆栈跟踪

May 9, 2012 9:35:56 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
 (, )
   at java.lang.Class.getMethod(Class.java:1605)
   at javax.el.BeanELResolver.invoke(BeanELResolver.java:405)
   at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:147)
   at org.apache.el.parser.AstValue.getValue(AstValue.java:159)
   at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
   at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:989)
   at org.apache.jsp.WEB_002dINF.jsp.tables.WatchAllTable_jsp._jspx_meth_c_005fout_005f8(WatchAllTable_jsp.java:1132)
   at org.apache.jsp.WEB_002dINF.jsp.tables.WatchAllTable_jsp._jspx_meth_c_005fforEach_005f0(WatchAllTable_jsp.java:412)
   at org.apache.jsp.WEB_002dINF.jsp.tables.WatchAllTable_jsp._jspService(WatchAllTable_jsp.java:127)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
   at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
   at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
   at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:662)
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [spring] in context with path [/watch] threw     exception [An exception occurred processing JSP page /WEB-INF/jsp/tables/WatchAllTable.jsp at     line 77

74:                        <c:set var="rawDate" value="${result.getDate()}"/>
75:                        <c:set var="rawTime" value="${result.getTime()}"/>
76:                        
77:                        <td id="formattedDate" class="center"><c:out value="${rawDate.substring(4,6)}"/>/<c:out value="${rawDate.substring(6,8)}"/></td>
78:                        <td id="formattedTime" class="center"><c:out value="${result.getTime().substring(0,2)}"/>:<c:out value="${result.getTime().substring(2,4)}"/></td>
79:                        <td id="documentGroup" class="hidden"><c:out value="${curDocGroup}"/>    </td>

以下链接看起来像解决了这个问题,但我不明白他们在说什么。

http://forum.springsource.org/showthread.php?108175-SpEL-does-not-recognize-functions&s=e077b42fd45ae3a3177a01c90339893c

由于

2 个答案:

答案 0 :(得分:6)

EL(表达语言,那些${}件事)将数字视为long,而real method只需要int个数字。这解释了这个例外。

您需要JSTL fn:substring()

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<c:set var="rawDate" value="${result.date}"/>
<c:set var="rawTime" value="${result.time}"/>
<c:out value="${fn:substring(rawDate,4,6)}"/>/<c:out value="${fn:substring(rawDate,6,8)}"/>
<c:out value="${fn:substring(rawtime,0,2)}"/>:<c:out value="${fn:substring(rawtime,2,4)}"/>

或更好,只需直接使用正确的工具,将其作为java.util.Date存储在模型中,然后使用JSTL <fmt:formatDate>

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
...
<fmt:formatDate value="${result.realJavaUtilDate}" pattern="MM/dd HH:mm" />

对其拥有的数据使用正确的数据类型。

答案 1 :(得分:2)

你也可以做以下事情。

    <c:set var="rawDate" value="${result.getDate()}"/>
    <c:set var="rawTime" value="${result.getTime()}"/>
    <td id="formattedDate" class="center"><c:out value="${rawDate.substring(Integer.parseInt(\"4\"), Integer.parseInt(\"6\")}"/>/<c:out value="${rawDate.substring(Integer.parseInt(\"6\"), Integer.parseInt(\"8\")}"/></td>
    <td id="formattedTime" class="center"><c:out value="${result.getTime().substring(Integer.parseInt(\"0\"), Integer.parseInt(\"2\")}"/>:<c:out value="${result.getTime().substring(Integer.parseInt(\"2\"), Integer.parseInt(\"4\")}"/></td