1

I am new to spring.My task is to do design and code for login and some CURD operations by using spring,hibernate and jsp.I need to pass list values from logincontroller to anothercontroller.

public ModelAndView loginProcess(HttpServletRequest request, HttpServletResponse response){  
          //..... 
          return new ModelAndView(new RedirectView("/dvd_hibernate/DvdController/dvdCURDOperation"),"userDetails",userDetails);}

I redirected to DvdController as well as passing userDetails.Is it the correct way to do?if so how to retrieve the userDetails value in anothercontroller? I didnot used annotations. please make me to clear.


Why can't you call dvdCURDOperation method directly within loginProcess.

If you are aiming a 302 redirect so that browser url changes to

/dvd_hibernate/DvdController/dvdCURDOperation

you will have to save userDeatils in Session and retrieve it in dvdCURDOperation method.

request.getSession.setAttribute("userDetails", userDetails);
return new ModelAndView("redirect:/dvd_hibernate/DvdController/dvdCURDOperation");
4

3 回答 3

2

I think what you're looking for is session variables in Spring. There's actually 4 ways of doing it, each with its pros and cons. You can find more details in the following link. It provides one of the best explanation on this topic on the net.

Richard Chesterwood's "Using Sessions in Spring-MVC"

于 2012-12-10T11:42:42.920 回答
1

为什么不能直接在 loginProcess 中调用 dvdCURDOperation 方法。

如果您的目标是 302 重定向,以便浏览器 url 更改为

/dvd_hibernate/DvdController/dvdCURDOperation

您必须在 Session 中保存 userDeutils 并在 dvdCURDOperation 方法中检索它。

request.getSession.setAttribute("userDetails", userDetails);
return new ModelAndView("redirect:/dvd_hibernate/DvdController/dvdCURDOperation");
于 2012-12-10T10:38:20.750 回答
0

As you've no doubt discovered by now, passing a ModelMap to a RedirectView will have no effect. Others have mentioned session variables, but if you'd prefer to keep your controllers stateless, you can pass any arguments you need as URL parameters.

于 2012-12-10T14:43:36.590 回答