Reputation: 2296
I am trying to make a redirection once a transaction is performed, though the transaction never gets executed. The most surprising thing is that when I click a submit button I do get this cloaked URL redirection which I do not understand why? My controller code:
@RequestMapping("/saveCyclosUsers")
public ModelAndView saveCyclosUsersCredentials(@ModelAttribute("cyclosUsers") CyclosUsers cyclosUsers, BindingResult bindingResult)
{
cyclosUsersService.saveCyclosUsers(cyclosUsers);
System.out.println("Cyclos Users List:");
return new ModelAndView("redirect/cyclosUsersList.html");
}
My JSP page:
<c:url var="userRegistration" value="saveCyclosUsers.html"/>
<form:form id="registerForm" modelAttribute="cyclosUsers" method="post" action="${userRegistration}">
The DAO code:
@Override
public void saveCyclosUsers(CyclosUsers cyclosUsers) {
//sessionFactory.getCurrentSession().save(cyclosUsers);
sessionFactory.getCurrentSession().createSQLQuery("INSERT INTO lower_credit WHERE" +"WEB-INF.views.Register.ownerName.selectedItem =" + "owner_name");
}
Once i click on the submit button this is what error I do get: type Status report
message /CyclosProjectOnOverdraft/WEB-INF/views/redirect/cyclosUsersList.html.jsp
description The requested resource is not available.
The extensions is the problem "cyclosUsersList.html.jsp" , html.jsp. I think it's weird. What am I doing wrong?
Upvotes: 0
Views: 211
Reputation: 2425
You probably have a ViewResolver in your spring mvc applicationContext with the suffix set to '.jsp'. So spring by default appends '.jsp' to your view name.
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
To avoid using a view resolver you could directly return a 'View' object, then no view resolver is used. You could also use @ResponseBody, then view resolver is bypassed.
Upvotes: 0
Reputation: 9655
Use:
return new ModelAndView("redirect:cyclosUsersList.html"); // Not redirect/cyclosUsersList.html
Upvotes: 1