Deny direct access to JSP files in Struts2 with Naming Convention plugin

前端 未结 1 882
臣服心动
臣服心动 2020-12-10 21:33

I\'ve been struggling with this issue as I\'m new to Struts2 development, and just started using this naming Convention Plugin recently.

I\'m trying to create a simp

相关标签:
1条回答
  • 2020-12-10 21:46

    Here how d'you want to disable this feature. Create a dummy bean

    package com.struts.handler;
    
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.Result;
    import com.opensymphony.xwork2.UnknownHandler;
    import com.opensymphony.xwork2.XWorkException;
    import com.opensymphony.xwork2.config.entities.ActionConfig;
    
    /**
     * Created by Roman C on 22.03.2015.
     */
    public class MyUnknownHandler implements UnknownHandler {
      @Override
      public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException {
        return null;
      }
    
      @Override
      public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws XWorkException {
        return null;
      }
    
      @Override
      public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException {
        return null;
      }
    }
    

    Then configure it in the struts.xml:

      <bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.struts.handler.MyUnknownHandler"/>
      <unknown-handler-stack>
        <unknown-handler-ref name="handler"/>
      </unknown-handler-stack>
    

    Explained here:

    The convention plugin along with configuration it creates mentioned above also put an unknown handler which should handle URLs for which a configuration is not exist (i.e. not created by the convention). This is the source of the problem.

    Now putting your own handler will disable convention's one. Thus it will no longer handle results by convention.

    0 讨论(0)
提交回复
热议问题