2

I am using tiles2 and spring in my project. When i am redirecting from spring controller to a jsp(the jsp page is mapped in tiles.xml file) page using query string like:

return "showRes.jsp?subSucc=ok";

it shows me:

javax.servlet.ServletException: Could not resolve view with name 'showRes.jsp?subSucc=ok'

I think this is wrong way to passing data using query string. Please tell me how can i do this.

Thanks Shams

Shams
  • 3,637
  • 5
  • 31
  • 49

1 Answers1

2

The Problem is that return "showRes.jsp?subSucc=ok"; statment should return the name of a jsp and it is NOT a URL.

The normal Spring way to pass values is a jsp is to use a Model Map (of course there are some other ways, but this is the easysest to describe one).

Have a look at the ModelAndView and Model class. Create an instance of it, set the view name and add your parameter, and then return it instead of the String.

Model model = new Model();
model.addAttribute("subSucc","ok");
ModelAndView modelAndView = new ModelAndView("showRes.jsp", model);
//may without ".jsp" postfix - this depends on your configuration
return modelAndView;
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Thanks for your response. I am using Model and ModelAndView. But i want to pass data as a querystring so that i can do something in javascript. Is there any way to pass value in querystring?? – Shams Mar 14 '11 at 10:44
  • @shams haque: I think you need to pass the values from the ModelMap in a javascript variable within you jsp: `` – Ralph Mar 14 '11 at 11:29
  • Thanks for the tip. I have done it by using object of ModelAndView, mav.addObject("subSucc", "shams"); and on jsp: . The is not working in script. May be it can also work with ModelMap. – Shams Mar 14 '11 at 13:22