0

I am tryying to implement a very simple Spring MVC application however not interested in binding a bean or model as I simply want to transfer value from one view to another through the controller.

Consider the following:

I have a simple searchForm

<form id="searchForm" name="searchForm" method="POST">
    <input name="test" name="test"/>
    <input type="submit" value="Submit"/>
 </form>

I then have a method in the controller which intercepts the post request:

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processSubmit(ModelMap model, HttpServletRequest httpRequest)  
{   
    return new ModelAndView("Results", model);
}

I now want to read the value submitted in the "test" input so in Results view I have:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

    <body>

        <c:out value="${test}"/>
    </body>

But I don't see the value submitted.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Joly
  • 3,218
  • 14
  • 44
  • 70

1 Answers1

1

You can access arbitrary request parameters using the paramValues map, e.g.

<c:out value="${paramValues.test}"/>

This is basic JSP, nothing to do with Spring.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Thanks got it eventually. You are right, I'm so into trying this with Spring that forgot all about basic jsp :) – Joly Jan 31 '12 at 18:40
  • What if I need to read the value from the Spring Controller and not from the Results view? – Joly Jan 31 '12 at 19:41
  • @Roy: Then you need to go and read up on how Spring MVC works. – skaffman Jan 31 '12 at 20:08
  • I have and I am able to do it by binding a model to the form however since I only need to transfer one string I find this meethod a bit cumbersome. I noticed I can add a string attribute to the model map however the form expects binding of an object with get and set methods so a bit confused of how to do it when all I need is to read one string and not a bean – Joly Feb 01 '12 at 06:10