简体   繁体   中英

spring3 - change the action method

On Spring with annotations, is there anyway that i can change the form action without changing the action using javascript?

For example on submit1 method invoked on the controller = method1
on submit2 method invoked on the controller = method2

@RequestMapping("/submit1")
public String submit1()

@RequestMapping("/submit2")
public String submit2()

...

<form:form id="dynamicfrm" method="post" action="archive/submit.do" commandName="submit">
 <input type="submit1" value="">
 <input type="submit2" value="">

Thank you!

If I understand you correctly - as others already said it isn't absolutely clear - than you want to map one single form to different action methods dependending on the button that was clicked.

In your JSP you can change the code to something like this:

<form action="/submit.do" method="post">
  <input type="submit" name="action" value="show">
  <input type="submit" name="action" value="edit">
</form>

And in your controller you can narrow the mappings like this:

@RequestMapping(value = "/submit", params="action=show")
public String showEntity() { /* ... */ }

@RequestMapping(value = "/submit", params="action=edit")
public String editEntity() { /* ... */ }

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