Roberto Gentili Roberto Gentili - 4 months ago 28
Java Question

Problems on retrieving object on a JSP using ValueStack

I put an object in the Struts2's

ValueStack
inside the intercept method of my interceptor using this code:

public String intercept(ActionInvocation invocation)
ValueStack vS = invocation.getStack();
vS.set("mainViewComponent", new MainViewComponent());
...
}


and I try to retrieve it on the jsp using this code

<s:property value="#mainViewComponent.contextPath" />


but this exception is thrown

Caused by: java.io.IOException: JSPException including path '/_common/layout/fragments/httpHeader.jsp'.
at org.apache.tiles.request.servlet.ServletUtil.wrapServletException(ServletUtil.java:61) [:1.0.1]
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:125) [:1.0.1]
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47) [:1.0.1]
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45) [:1.0.1]
at org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68) [:1.0.1]
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259) [:3.0.1]
at org.apache.tiles.TilesContainerWrapper.render(TilesContainerWrapper.java:108) [:3.0.1]
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188) [:3.0.1]
at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132) [:3.0.1]
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299) [:3.0.1]
at org.apache.jsp._005fcommon.layout.base_jsp._jspx_meth_tiles_005finsertAttribute_005f0(base_jsp.java:161)
at org.apache.jsp._005fcommon.layout.base_jsp._jspService(base_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:541) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.1.0.Final]
at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265) [:1.0.1]
... 88 more
Caused by: source is null for getProperty(null, "contextPath") - Class: ognl.OgnlRuntime
File: OgnlRuntime.java
Method: getProperty
Line: 2310 - ognl/OgnlRuntime.java:2310:-1
at com.opensymphony.xwork2.ognl.OgnlValueStack.handleOgnlException(OgnlValueStack.java:331) [:2.3.14.2]
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:309) [:2.3.14.2]
at org.apache.struts2.components.Property.start(Property.java:159) [:2.3.14.2]
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53) [:2.3.14.2]
at org.apache.jsp._005fcommon.layout.fragments.httpHeader_jsp._jspx_meth_s_005fproperty_005f0(httpHeader_jsp.java:118)
at org.apache.jsp._005fcommon.layout.fragments.httpHeader_jsp._jspService(httpHeader_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:639) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:576) [:6.1.0.Final]
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968) [:6.1.0.Final]
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:650) [:6.1.0.Final]
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:644) [:6.1.0.Final]
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123) [:1.0.1]
... 111 more
Caused by: ognl.OgnlException: source is null for getProperty(null, "contextPath")
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2310) [:]
at ognl.ASTProperty.getValueBody(ASTProperty.java:114) [:]
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) [:]
at ognl.SimpleNode.getValue(SimpleNode.java:258) [:]
at ognl.ASTChain.getValueBody(ASTChain.java:141) [:]
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) [:]
at ognl.SimpleNode.getValue(SimpleNode.java:258) [:]
at ognl.Ognl.getValue(Ognl.java:494) [:]
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:255) [:2.3.14.2]
at com.opensymphony.xwork2.ognl.OgnlValueStack.getValue(OgnlValueStack.java:356) [:2.3.14.2]
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValue(OgnlValueStack.java:345) [:2.3.14.2]
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValueWhenExpressionIsNotNull(OgnlValueStack.java:321) [:2.3.14.2]
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:307) [:2.3.14.2]
... 130 more


Someone could understand where is the problem?

Answer

In the JSP you have included the header fragment, but the URL used to get the resource isn't working because it contains an OGNL expression that unable to evaluate, because it references to the null object.

Now I see you posted ho do you retrieve the URL

<s:property value="#mainViewComponent.contextPath" />

And error is that #mainViewComponent referenced the ActionContext property which is null because you didn't put the object to it, but you put it in the valueStack so should get

<s:property value="mainViewComponent.contextPath" />