Search code examples
jspspring-mvcjsp-tagsquery-string

Spring MVC post back to same page with query params?


I have an index.jsp per spring mvc 3.x that contains a drop down list box.

What is the easiest way to post back to the same page but with query params per the selected item in the list?

myPage/index.jsp (http://localhost:8085/mypage)

   <form class="form-horizontal" action="myController/indexSubmit" method="post">
        <select name="selectList" class="form-control" placeholder=".input-medium" height>
            <c:forEach items="${theList}" var="item" varStatus="count"> 
                <option value="${count.index}">${item }</option>
            </c:forEach>
        </select>   
        <button type="submit" class="btn btn-primary btn-medium">Submit</button>   
    </form>

->http://localhost:8085/GameAnalytics?selectedItem=3

I have tried using a postback to redirect back to /index doesn't seem to be working.

@RequestMapping(value="indexSubmit", method = RequestMethod.POST)
public String indexSubmit( @RequestParam String selectList, ModelMap model) {
    System.out.println("Selected Title: " + selectList);
    return "forward:/index?item=" + selectList;  // add query params and redirect back to main index page.
}   

Solution

  • try return "redirect:index?item=" + selectList;