0

I do not know what configuration changes I may have done to cause this, but for some reason, going to an invalid URL which maps to no struts2 action, only gives a blank page. It does not redirect to the Mapped 404 page, and it does not even display the "There is no Action mapped for namespace [/] and action name []" like it used to. I am trying to get my 404 page working, but I have no clue what is going on here. In my web.xml I have:

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

<error-page>
    <error-code>404</error-code>
    <location>/jsp/error/404.jsp</location>
</error-page>

Have any idea as to why blank pages are being served with invalid URL's and actions? I appreciate the help

Jon McPherson
  • 2,495
  • 4
  • 23
  • 35
  • This question lacks the configuration. – Roman C Jan 22 '14 at 09:04
  • @RomanC Actually the problem was pretty dumb... with the location to the 404.jsp was wrong. The solution was to have /WEB-INF/jsp/error/404.jsp but I excluded the WEB-INF directory because web.xml is stored in that so I figured that's where it would check. – Jon McPherson Jan 22 '14 at 17:16
  • Sorry, I can't understand, could you post your JSP? – Roman C Jan 22 '14 at 17:25

1 Answers1

3

Finally - After deep searching about this issue, I'll find a great solution to how get this works as probably!

1st: you need to add the com.opensymphony.xwork2.UnknownHandler bean in your struts.xml:

<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.path.to.your.InvalidRequests"/>


2nd: setup an action to refer into the page not found behavior.

<action name="pageNotFound" class="com.path.to.your.PageNotFound" method="execute">
   <result name="success">/jsps/404.jsp</result>
</action>


3rd: in your custom handler you need to define your com.opensymphony.xwork2.config.entities.ActionConfig and check if the action is already exists in your action configuration lists

public class InvalidRequests implements UnknownHandler {
@Override
public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException {
    ConfigurationManager configurationManager = Dispatcher.getInstance().getConfigurationManager();
    RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
    if(actionConfig == null) { // invalid url request, and this need to be handled
        actionConfig = runtimeConfiguration.getActionConfig("", "pageNotFound");
    }
    return actionConfig;
}
// ... also you need to implements handleUnknownResult, handleUnknownActionMethod
}


Keep in mind you need to override the both of methods handleUnknownResult and handleUnknownActionMethod and the both of methods return null.

Ahmad AlMughrabi
  • 1,612
  • 17
  • 28
  • In second step what is the class com.path.to.your.PageNotFound for? – user2693404 Feb 27 '20 at 09:29
  • It is an action class that you need to create it for 404 requests. Something like this should work: public class NotFound extends ActionSupport { @Override public String execute() { return ERROR; } } – Ahmad AlMughrabi Mar 02 '20 at 11:54