Domanda

How can i catch this parameter in my Struts2 Custom Interceptor, send from a JSP page ?

<s:url var="remoteurl" action="jsontable">
    <s:param name="gridName">gridTableID</s:param>
</s:url>
  <sjg:grid
        id="gridTableID"

        caption="Customer Examples (Local Data)"
        href="%{remoteurl}"
        gridModel="gridModel"
        rowNum="-1"
        hidegrid="true"
....

Edit: My custom stack:

<interceptors>
            <interceptor name="logingInterceptor" class="com.interceptors.LoggingInterceptor"></interceptor>
            <interceptor-stack name="newStack">
                <interceptor-ref name="logingInterceptor" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="newStack"></default-interceptor-ref>
È stato utile?

Soluzione

EDIT 2: if your interceptor can't get the request parameters, I suggest an atomic approach to the problem. Try small steps, resolve problems one by one. In your case, i'll try as follows:

1) Put a debug "hello interceptor" inside your interceptor, to see if the call to your action is actually passing THROUGH your custom interceptor.

If not: check your settings (interceptor, interceptors-stack, packages, actions etc).

If yes:

2) Put a normal variable in the form you are posting in a classic way (not ajax or something, just a <s:hidden name="foo" value="blabla"/> variable inside your form in the JSP, posted with an <s:submit button to your action (the actiop mapped for using the interceptor stack with your custom interceptor). Try to print out the value of that variable from the interceptor.

If variable is null: check your action mappings again, use Firebug Net module to see if the parameters is actually posted out, etc.

If variable is read:

then the problem is in the variable of the JQGrid, check the way you are referencing it in the JSP and what is going out of the page with Firebug again.

Etc...

I suggest you to use a new JSP with only your stuff inside, with a new action for displaying and receiving the result, with an empty execute()... just a very very tiny skeleton to test your code being sure nothing external is messing up the worflow...


EDIT: your Interceptors configuration seems fine (except for defaultStack instead of default-stack, but I'm pretty sure it's the same).

Are all of your Actions inside the same <package> in which the <interceptors> is defined ?


Why on the Interceptor and not in the Action ? How do you need to handle that data ?

By the way, this is the code:

public String intercept(ActionInvocation invocation) throws Exception {

   final ActionContext context = invocation.getInvocationContext();
   HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST);

   String gridName = (String) request.getParameter("gridName");

   /* do something */

   return invocation.invoke();
}

Altri suggerimenti

Try this. It worked for me in struts 2.0.14.

public String intercept(ActionInvocation ai) throws Exception {
            ActionConfig config  = ai.getProxy().getConfig();  
            Map parameters       = config.getParams();  
            String menuId        = (String)parameters.get("empName"); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top