Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to differentiate methods with @RequestAnnotations with same parameters in Spring Web MVC?
    primarykey
    data
    text
    <p>I entered in <strong>Spring Web MVC Framework</strong> not long ago thus I am a complete beginner.</p> <p>The issue I have is the following. I have a file named <em>myForm.jsp</em> where am I presenting some text, tables, etc. . Besides that I have also <strong>2 froms with two appropriate buttons</strong> (<em>see the code below</em>).</p> <hr> <pre class="lang-jsp prettyprint-override"><code>&lt;!-- code --&gt; &lt;form:form id="form1" method="post" commandName="firstForm"&gt; &lt;!-- code --&gt; &lt;input class="button" type="submit" value="Submit" name="submit"/&gt; &lt;/form:form&gt; &lt;!-- code --&gt; &lt;form:form id="form2" method="post" commandName="secondForm"&gt; &lt;!-- code --&gt; &lt;input class="button" type="submit" value="Save" name="save"/&gt; &lt;/form:form&gt; &lt;!-- code --&gt; </code></pre> <hr> <p>Now I am interested in handling both submit actions in a <strong>FromController.java</strong></p> <pre class="lang-java prettyprint-override"><code>package si.src.controllers; import java.util.ArrayList; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import si.src.forms.Obrazec; @Controller public class ObrazecFormController { @RequestMapping(value="/spletniObrazec", method=RequestMethod.POST) public String submitTheFromButton1(){ //logic for button1 //additional code } @RequestMapping(value="/spletniObrazec", method=RequestMethod.POST) public String submitTheFromButton2(){ //logic for button2 //additional code } } </code></pre> <hr> <p>Is there a way how to tell Spring to distinguish between two methods? Perhaps with additional <strong>@annotations</strong> or <strong>name/value</strong> properties in form:form tag?</p> <p>I also tried writing different controller classes but it doesn't work since this Spring MVC is behaving in a event-driven manner.</p> <p>Probably I am missing the whole concept of controllers, methods and annotations so I will really appreciate any advice/idea/suggestion/solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload