struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken McWilliams <>
Subject Understanding Struts2 Internals : Result Configuration
Date Fri, 06 Sep 2013 05:46:19 GMT
The following is a direct copy of a question at SO which has been repeated
here for completeness but can be found here with nice syntax highlighting :

In an effort to understand how struts2 loads its configuration I wanted to
display the path to the JSP which would be rendered. Given the following
very minimal struts.xml:

    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="simple" />

    <package name="base" namespace="/">
            <result-type name="dispatcher"
        <action name="test" class="com.kenmcwilliams.badwebapp.action.Test">

I want to be able to log "/WEB-INF/content/test.jsp" from within the
action. Given the following action:

package com.quaternion.badwebapp.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.PreResultListener;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Test extends ActionSupport {
    //used for a sanity test on JSP
    public String getMessage() {
        return "From test";

    public String execute() throws Exception {
" + ActionContext.getContext().getActionInvocation().getResultCode());
        ActionInvocation ai = ActionContext.getContext().getActionInvocation();
        ai.addPreResultListener(new PreResultListener() {
            public void beforeResult(ActionInvocation invocation,
String resultCode) {
                try {
                    System.out.println("PreResultListener resultCode:
" + resultCode);
                    System.out.println("PreResultListener result: " +
                } catch (Exception ex) {

Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        return SUCCESS;

There are three print statements which produce the following output on my

INFO:   ActionContext.getContext().getActionInvocation().getResultCode(): null
INFO:   PreResultListener resultCode: success
INFO:   PreResultListener result: null

>From testing both the result "invocation.getResult()" and the resultcode is
null *before* the PreResultListener is called but *within* the
PreResultListener the resultcode is set, yet the result still returns null!

>From the JavaDoc of the getResult() method:

If the ActionInvocation has been executed before and the Result is an
instance of {@link ActionChainResult}, this method will walk down the chain
of ActionChainResult's until it finds a non-chain result, which will be
returned. *If the ActionInvocation's result has not been executed before,
the Result instance will be created and populated with the result params.*

Seems pretty clear that a result instance is *not* being created.

So how do I display "/WEB-INF/content/test.jsp" within this action? This is
not for typical struts2 use, I'm want to test a configuration provider for
which there is something wrong with the construction of the result for the
action, hopefully understanding why this isn't working will let me fix that

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message