How to compare a single character from url request parameter in Struts 2

前端 未结 1 1791
走了就别回头了
走了就别回头了 2021-01-25 13:22

I am reading the url parameter which has a single character. It will either be Y or N. I have to write a condition to check if it Y or

相关标签:
1条回答
  • Usually request parameters are processed by the params interceptor. The action configuration should have this interceptor included in the stack. If you not referencing this interceptor explicitly the defaultStack is used that already contains the params interceptor. What you need is the package for the action to be extended the "struts-default".

    <package name="default" namespace="/" extends="struts-default">
    

    Then parameters will be processed and put to the action attributes, where you could access them via OGNL by implementing getter and setter.

    Another way is to implement ParameterAware by your action. After injecting parameters it could be available from the action that is on top of the valueStack and you could get parameters via

    <s:if test="parameters['theconditionTypeInUrl'] == 'Y'">  
    

    after adding getter for parameters attribute

    Map getParameters(){
      return this.parameters;
    }
    

    More detail explanation you could find here.

    The way you are trying access request parameters from the action context map via OGNL using #parameters key. There could be troubles accessing parameters in the if tag, see here.

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