Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I pass a query within a spring mvc controller?
    primarykey
    data
    text
    <p>assume you have something like this in normal servlet without using spring mvc:</p> <pre><code>if(username == "X" &amp;&amp; password =="Y"){ response.sendRedirect("./user/welcomePage.jsp"); }else{ response.sendRedirect("./login.jsp?wrongPass=true"); } </code></pre> <p>and if the username &amp;&amp; password is wrong, after redirection to login.jsp page, inform user that the username or password is wrong, somewhere in the login.jsp page in red color:</p> <pre><code>&lt;p style="color:red"; &lt;%= (request.getParameter("wrongPass")==null)? "visibility:hidden":"" %&gt;;"&gt; Your username/password is wrong !&lt;/p&gt; </code></pre> <p>My question is, is there any way to pass an argument like:</p> <pre><code>response.sendRedirect("./login.jsp?wrongPass=true"); </code></pre> <p>inside Spring MVC controller ?</p> <p>coz if we have a controller like this:</p> <pre><code>@Controller @RequestMapping(value ="/") public class Welcome{ public String welcome(@RequestParam("j_username") String username, @RequestParam("j_password") String password){ . . . return "login"; </code></pre> <p>as log as we need to return a String to form a page &amp; because we have InternalResourceViewResolver defined:</p> <pre><code>&lt;bean &gt;class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/WEB-INF/views/" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; </code></pre> <p>if we pass the argument in our controller like: return "login?wrongPass=true" after using InternalResourceViewResolver that will create something like :</p> <pre><code>login?wrongPass=true.jsp Which is totally wrong ... </code></pre> <p>now, what is your solution to solve this problem (without) adding that String to model inside our controller &amp; fetch the parameter inside JSP ? I want the browser url become something like: </p> <pre><code>http://localhost:8080/myProject/login.jsp?wrongPass=true </code></pre>
    singulars
    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