简体   繁体   中英

struts form action not being called

I'm working on an application that uses struts, and I don't fully understand struts yet;

If I have the following in a jsp page:

<form action="/accountProcess" class="" id="" method="post" enctype="multipart/form-data" autocomplete="off">
  <select name="user_status_filter">
    <option value="no_filter">no filter</option>
    <option value="inactive">Inactive</option>
    <option value="active">Active</option>
  </select>

  <input type="submit" value="submit"/>
</form>

and inside my struts-confix.xml:

<action-mappings>
     <action path="/accountProcess"
            name="UserForm"
            type="x.y.UserAction"
            scope="request"
            parameter="dispatch"
            input="pages.account"
            validate="false"
            roles="user">
     </action>
</action-mappings>

and inside my UserAction class:

public ActionForward getUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
    String requestValue = RequestUtils.getStringParameter(request, "user_status_filter");


    return mapping.findForward("adminView");
}

How do I get my form to call the getUsers method in my UserAction class? Do I have to pass some hidden parameter in my form, and if so, how do I do this? In my form, is my action attribute set correctly? And would the form method be post or get?

found the solution, I added a hidden field for the html where the value is the name of the method

<form action="/accountProcess" class="" id="" method="post" enctype="multipart/form-data" autocomplete="off">
<html:hidden property="dispatch" value="getUsers" />
  <select name="user_status_filter">
    <option value="no_filter">no filter</option>
    <option value="inactive">Inactive</option>
    <option value="active">Active</option>
  </select>

  <input type="submit" value="submit"/>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM