在我的jsp页面上单击一个锚标签后,它完全有效,但是在控制台中会抛出以下异常,基于this answer,我从我的依赖项文件夹中删除了jap-api*.jar
文件但是应用程序仍然抛出异常。
WARNING: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.products.ProductShow_jsp._jspx_meth_c_if_1(ProductShow_jsp.java:211)
at org.apache.jsp.products.ProductShow_jsp._jspService(ProductShow_jsp.java:119)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:977)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:701)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
at org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.TilesContainerWrapper.render(TilesContainerWrapper.java:108)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
at org.apache.jsp.baseLayout_jsp._jspx_meth_tiles_insertAttribute_3(baseLayout_jsp.java:166)
at org.apache.jsp.baseLayout_jsp._jspService(baseLayout_jsp.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
at org.apache.tiles.TilesContainerWrapper.render(TilesContainerWrapper.java:103)
at org.apache.tiles.impl.mgmt.CachingTilesContainer.render(CachingTilesContainer.java:126)
.....
WARNING: Servlet.service() for servlet jsp threw exception
java.io.IOException: JSPException including path '/products/Product.jsp'.
at org.apache.tiles.request.servlet.ServletUtil.wrapServletException(ServletUtil.java:61)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:125)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
代码
<div id="product">
<table>
<tbody>
<tr><td>ID:${product.id}</td></tr>
.....
</tbody>
</table>
<sec:authorize access="hasAnyRole('ROLE_ADMIN')">
<c:if test="${product.available}">
<s:if test="%{availability > 1}">
<a href="" onclick="remove(${product.ID})">Remove</a>
</s:if>
<s:else>
<c:if test="${cookie.containsKey('id')}">
<a href="" onclick="add(${product.ID})">Add</a>
</c:if>
<c:if test="${!cookie.containsKey('id')}">
<a href="index.jsp">index</a>
</c:if>
</s:else>
</c:if>
</sec:authorize>
</div>
删除和添加与他们自己的javascript函数相关联,这两个函数完美地工作但异常将被抛出,并且从javascript函数返回后,页面显示正确的结果。
答案 0 :(得分:3)
你可以通过一些工作来实现这一点。 JSP被编译为servlet,源代码可以在Web服务器的工作文件夹下找到。一般来说,找到'work'文件夹,然后深入了解包,这对于Tomcat通常是org.apache ....(抱歉不能记住确切的,这台机器没有安装Tomcat)。只需向下钻取,您应该找到ProductShow_jsp.java源代码。转到指定的行号,您通常可以找出异常的原因。
答案 1 :(得分:1)
请检查以下建议是否消除了错误:
a)检查是否定义了product.id或product.ID
b)检查product.available
的属性名称是否正确 c)添加<c:if test="${product.available}">