How to access url parameters in Action classes Struts 2

后端 未结 4 1459
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 07:39

I\'m new to Java EE and Struts2. I need to know if I\'m doing it wrong or not.

I\'ve got a link like this : http://localhost:8080/myProject/deleteUser?idUser=42

4条回答
  •  天命终不由人
    2020-12-15 07:50

    Try this:

    ActionContext context = ActionContext.getContext();
    Map params = context.getParameters();
    String userId = findParam("idUser", params);
    
    public String findParam(String key, Map params) {
      Object obj = params.get(key);
      if(obj != null) {
        String[] values = (String[])obj;
        return values.length > 0 ? values[0] : null;
      } 
      return null;
    }
    

提交回复
热议问题