I am new to Spring MVC Restful. Suppose I have index.jsp that redirects the user to a form page where the user can submit a term to search. I caught this term using the POST handler method, and then I do some calculations and hope to redirect the result to be used on another page (/ WEB-INF / jsp), for example, we say that we will build a graph based on the result. The problem is how to collect the results and redirect the URL at the same time. Controllers as shown below:
@RequestMapping(value="/termForm", method = RequestMethod.GET) public ModelAndView setupForm() { Term termClass = new Term(); return new ModelAndView("term", "command", termClass); } @RequestMapping(value="/getTerm", method=RequestMethod.POST) public String getTerms(@ModelAttribute("term") Term term, BindingResult result) { String label = term.getTerm();
When searching, I found that Spring View Resolver can handle redirected jsp under the root directory (same as index.jsp). In this case, the "result" seems to be not accepted by the "graphPage". I also included UrlBasedViewResolver in XXX-servlet.xml as follows:
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>
Sorry for the long question, please give at least some hint of this. Thank you very much.
There are two parts to my question. One of them redirects the POST method to another page, graphPage.jsp. As we move on to the graph, we need data from the POST method, as well as to create the graph. This is another problem. Hope this is clear. I already solved the first by adding a handler method, see below. But how to pack the result and pass it to Graph.jsp? Thanks
@RequestMapping(value="/graphPage", method=RequestMethod.GET) public String showGraph() { return "graphPage"; }
source share