I am currently trying to return a model from onSubmit() in my controller. I then am trying to retrieve this in my jsp.
for example
Map model = new HashMap();
model.put("errors", "example error");
return new ModelAndView(new RedirectView("login.htm"), "model", model);
and then retrieving it with
<c:out value="${model.errors}"/>
However this does not display anything. it goes to the correct redirectview and does not issue any errors, but the text is not displayed.
Any help will be much appreciated.
thanks
What RedirectView does is sending a redirect header to the browser so browser does a complete reload of the page, as a result model does not get carried over there (as it is handled now by login controller with its own model).
What you can do is pass errors through request attributes:
In your views.properties:
loginController.(class)=org.springframework.web.servlet.view.InternalResourceView
loginController.url=/login.htm
Then instead of RedirectView return:
request.setAttribute("errors", "example errors");
return new ModelAndView("loginController");
And in your login controller check for this attribute and add it to the model.
Update: Without using views.properties:
request.setAttribute("errors", "example errors");
return new ModelAndView(new InternalResourceView("/login.htm"));
OR you can add (another) internal view resolver to your App-servlet.xml (Note from API: When chaining ViewResolvers, an InternalResourceViewResolver always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists.):
<bean id="viewResolver2"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
</bean>
And then just use:
request.setAttribute("errors", "example errors");
return new ModelAndView("/login.htm");