PDA

View Full Version : problems when using redirect: prefix


cujigar1
Aug 28th, 2005, 06:55 PM
http://localhost:8080/brinder/login.htm?org.springframework.validation.BindExcep tion.command=org.springframework.validation.BindEx ception%3A+BindException%3A+0+errors&command=brinder.User%4020224a

why do i see such crap in the redirected url.

i have two controllers register and login,



<bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUr lHandlerMapping"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean name="/login.htm" class="com.brinder.mvc.LoginController">
<property name="userDAOJDBC">
<ref bean="userDAO"/>
</property>

<property name="formView">
<value>login</value>
</property>
<property name="successView">
<value>index</value>
</property>
<property name="validator">
<bean class="com.brinder.mvc.UserValidator"/>
</property>

</bean>

<bean name="/register.htm" class="com.brinder.mvc.RegisterController">
<property name="userDAOJDBC">
<ref bean="userDAO"/>
</property>

<property name="formView">
<value>register</value>
</property>
<property name="successView">
<value>redirect:login.htm</value>
</property>
<property name="validator">
<bean class="com.brinder.mvc.UserValidator"/>
</property>

</bean>


first client visits /register.htm
presses submit button , registration accepted,
and successView property redirects to login.htm
but why do i see such rappy url in browser adress bar
http://localhost:8080/brinder/login.htm?org.springframework.validation.BindExcep tion.command=org.springframework.validation.BindEx ception%3A+BindException%3A+0+errors&command=brinder.User%4020224a

simtin
Aug 29th, 2005, 01:14 AM
Hi,

this is due to the fact that all kind of model properties are set as request parameters when being used in a redirect view. Maybe this thread: http://forum.springframework.org/showthread.php?t=17575 can help you.

Kind regards,
Simon

sergey_wba
Sep 20th, 2005, 01:21 AM
It is not good practice and somehow ugly, but it works:
You should override the processFormSubmission it SimpleFormController

...
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
ModelAndView mv = super.processFormSubmission(request, response, command, errors);
if (mv.getViewName().startsWith("redirect:"))
return new ModelAndView(new RedirectView(mv.getViewName().substring(9)));

return mv;
}
...

Colin Yates
Sep 20th, 2005, 05:56 AM
Try not to be too offensive with words like "crappy" as people won't respond kindly :)

As pointed out, RedirectView will convert everything in the model to parameterName=object.toString().

See http://opensource2.atlassian.com/projects/spring/browse/SPR-1294 for more info and a workaround.