Redirection of spring MVC page

As shown in the figure, jumping from a jsp page to the next jsp page usually requires the previous page to issue a request with parameters. We all know that spring MVC cannot jump pages directly.

You need to configure the view parser, and then jump to the corresponding JSP page by returning the view name.

Even so, the request from the previous page is displayed in the address bar of the next page, which is not only unsightly, but also when operating order data, pressing F5 to refresh the page may resubmit the order.

So this operation is extremely unsafe. Redirect is required.

We only need to write a method that redirects to a parameter (view name), and every method to jump to a page uses it, no need to write one by one. as follows:

/** 
* Redirect to the page where the request was successful
* @return
*/
@RequestMapping("/resultJsp/{jspUrl}")
public String resultJSP(@PathVariable("jspUrl") String jspUrl){
return jspUrl;
}

Call:

/**
* 跳转到新闻列表
* @param id
* @return
*/
@RequestMapping(value = "/static/toNewList/{id}")
public String toNewList(@PathVariable("id") int id,
HttpServletRequest request){
List<News> newlist=new ArrayList<News>();
switch (id){
case 1:
newlist=(List<News>)request.getSession().getAttribute("cardSals");
break;
case 2:
newlist=(List<News>)request.getSession().getAttribute("recruitList");
break;
case 3:
newlist=(List<News>)request.getSession().getAttribute("cooperationList");
break;
case 4:
newlist=(List<News>)request.getSession().getAttribute("concatList");
break;
case 5:
newlist=(List<News>)request.getSession().getAttribute("weList");
break;
}
request.getSession().setAttribute("newlist",newlist);
request.getSession().setAttribute("tid",id);
return "redirect:/resultJsp/newList";
}
The result is as follows:

 

Permission problem, you need to let go of the method at the beginning of resultJsp in the interceptor



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324946942&siteId=291194637