Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC Request Param
    text
    copied!<p>I have a login page with form action of <strong>j_security_check</strong>. As of now this form just have two fields namely username and password. I want to add a new dropdown to this form and collect the selected value in controller using <code>@RequestParam</code>. For some reason I am not able to pass this dropdown value from JSP to my controller as its throwing the <code>exception: MissingServletRequestParameterException</code> (Which occurs anytime a request param is missing).<br/> In the code below I added the Visuals dropdown. Do I need to use <code>Spring:Bind</code> tag here? Also on successful login, the control is directed to a controller with request mapping <strong>/controller1.html</strong> and this is where I am trying to collect the dropdown value.</p> <pre><code>&lt;form name="appLogin" action="j_security_check" method="POST"&gt; &lt;table width="100%"&gt; &lt;tr&gt; &lt;td align="center"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Username: &lt;/td&gt; &lt;td&gt;&lt;input id="userName" name="j_username" value=""/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password: &lt;/td&gt; &lt;td&gt;&lt;input name="j_password" type="password" value="" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Visual: &lt;/td&gt; &lt;td&gt;&lt;Select name="visuals" id="visuals"/&gt; &lt;option value="S1"&gt;S1&lt;/option&gt; &lt;option value="S2"&gt;S2&lt;/option&gt; &lt;option value="S3"&gt;S3&lt;/option&gt; &lt;option value="S4"&gt;S4&lt;/option&gt; &lt;/Select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;button type="submit" name="submit" value="Sign In"&gt;Sign In&lt;/button&gt; &lt;input type="submit"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>Controller Code: <br/></p> <pre><code> @RequestMapping( value = " /controller1.html", method = RequestMethod.GET ) public String setupForm( @RequestParam(value = "visuals", required=false) String visuals, ModelMap model ) { List&lt;String&gt; studentNames = new ArrayList&lt;String&gt;(); List&lt;String&gt; teacherNames = new ArrayList&lt;String&gt;(); model.addAttribute("someData", teacherNames); model.addAttribute("anotherData", studentNames); model.addAttribute("visuals", visuals); log.info("Role from Dropdown: " + visuals); return "school/classTen"; } </code></pre>
 

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