2013-03-17 105 views
5

我在爲自己的自定義taglib功能無法正常工作而b my不安。該示例使用Math.cosMath.sin非常簡單的自定義taglib功能不起作用

這裏的類:

package foo.tags; 
public class Math { 
    public java.lang.Double cos(java.lang.Double value) { 
     return java.lang.Math.cos(value); 
    } 
    public java.lang.Double sin(java.lang.Double value) { 
     return java.lang.Math.sin(value); 
    } 
} 

這裏的.TLD文件:

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" 
version="2.0"> 

<tlib-version>2.0</tlib-version> 
<uri>/WEB-INF/tags/math.tld</uri> 
<function> 
    <name>cos</name> 
    <function-class>foo.tags.Math</function-class> 
    <function-signature>java.lang.Double cos(java.lang.Double)</function-signature> 
</function> 
<function> 
    <name>sin</name> 
    <function-class>foo.tags.Math</function-class> 
    <function-signature>java.lang.Double sin(java.lang.Double)</function-signature> 
</function> 
</taglib> 

調用代碼的重要片段:

<%@ taglib prefix="math" uri="/WEB-INF/tags/math.tld" %> 
<span>${math:sin(180)}</span> 

我就得到一個空指針異常該行與math:sin(180)。有沒有人看到我在做什麼錯了?讓我知道是否需要更多的信息,但例外本身並不是非常豐富。謝謝!

編輯這裏的堆棧跟蹤:

Mar 17, 2013 2:27:14 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [Foo] in context with path [/Foo] threw exception [org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/svg/clock1.jsp at line 10 

[OTHER LINES REDACTED] 
10: <span>${math:sin(180)}</span> 
[OTHER LINES REDACTED] 

Stacktrace:] with root cause 
java.lang.NullPointerException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.apache.el.parser.AstFunction.getValue(AstFunction.java:112) 
    at org.apache.el.parser.AstMult.getValue(AstMult.java:39) 
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) 
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985) 
    at org.apache.jsp.<REDACTED> 
    at org.apache.jsp.<REDACTED> 
    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:432) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    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:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684) 
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593) 
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530) 
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954) 
    at org.apache.jsp.<REDACTED> 
    at org.apache.jsp.<REDACTED> 
    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:432) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    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:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471) 
    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:250) 
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) 
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) 
    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:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at Foo.page.filter.SimulationProgressFilter.doFilter(SimulationProgressFilter.java:88) 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at fOO.page.filter.CurrentSessionStateFilter.doFilter(CurrentSessionStateFilter.java:119) 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
+1

無論如何都有例外。 – BevynQ 2013-03-17 20:40:50

+0

好的,我添加了堆棧跟蹤,但我不得不用Foo替換我的實際類路徑,並在異常中編寫了JSP的非侵犯行(對不起,專有和諸如此類)。我希望它有幫助。 – 2013-03-17 20:46:11

回答

10

cossin方法需要被static

+0

哇,謝謝!那樣做了。多麼愚蠢的我...... – 2013-03-17 20:50:20

+0

在那裏,做到了,hehehe。很高興有幫助:) – 2013-03-17 20:51:28

相關問題