text: Q:
  
  Struts2: can't call action before rendering index.jsp
  
  I've searched for this all over SO, but didn't find a similar situation with the same symptoms. I'm using Sruts2 and trying to invoke an action before rendering the main page of my application (index.jsp). I truly believe that this action is not being called, because I have a System.out.println() (for debugging purposes) in the beginning of the execute() method of the action that is not being printed. Indeed index.jsp is being presented (because it is the default page), but the part that is related to the action is not being run. In conclusion, I think that the problem may reside in the struts.xml file. Below are both the struts.xml and the action file:
  Struts.xml:
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- The core configuration file for the framework is the default (struts.xml) file
  and should reside on the classpath of the webapp (generally /WEB-INF/classes). -->
  
  <!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd">
  
  <struts>
  
    <!-- devMode equals debug information and reload everything for every request -->
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="simple" />
  
    <package name="faultinjector" extends="struts-default">
  
      <default-action-ref name="loadexperiments" />
  
      <action name="loadexperiments" class="faultinjector.action.LoadExperimentsAction" method="execute">
        <result name="success">/index.jsp</result>
      </action>
  
    </package>
  
  </struts>
  
  LoadExperimentsAction.java:
  public class LoadExperimentsAction extends ActionSupport
  {
      private static final long serialVersionUID = 4L;
  
      private ExperimentService service;
      private List <Experiment> experiments;
  
      @Override
      public String execute()
      {
          System.out.println("Hello!");
  
          return SUCCESS;
      }
  
      public ExperimentService getService()
      {
          return service;
      }
  
      public void setService(ExperimentService service)
      {
          this.service = service;
      }
  
      public List<Experiment> getExperiments()
      {
          return experiments;
      }
  
      public void setExperiments(List<Experiment> experiments)
      {
          this.experiments = experiments;
      }
   }
  
  A:
  
  I finally managed to achieve what I was looking for, without the need of redirecting pages. Basically the solution is to keep my original configuration, but changing the JSP page name from "index.jsp" to another one (in my case, it is now called "user_main".jsp). This way, it oddly works, I guess it has some hidden default configuration parameter when using the default name "index.jsp". Content of my configuration files:
  web.xml:
  <web-app id="faultinjector" version="2.4"
  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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  
      <filter>
          <filter-name>struts2</filter-name>
          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
  
      <filter-mapping>
          <filter-name>struts2</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
  </web-app>
  
  struts.xml:
  <struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="simple" />
  
    <package name="faultinjector" extends="struts-default">
  
    <default-action-ref name="loadexperiments" />
  
    <action name="loadexperiments" class="faultinjector.action.LoadExperimentsAction" method="execute">
        <result name="success">/user_main.jsp</result>
      </action>
    </package>
  </struts>
  
  