How to redirect with POST variables with Spring MVC

前端 未结 1 1955
我寻月下人不归
我寻月下人不归 2021-01-13 04:58

I have written the following code:

@Controller
    @RequestMapping(\"something\")
    public class somethingControll         


        
1条回答
  •  再見小時候
    2021-01-13 05:15

    A spring Controller methods can be both POST and GET requests.

    In your scenario:

    @RequestMapping(value="/anotherUrl",method=RequestMethod.POST)
      public String myAnotherFunc(HttpServletRequest request,HttpServletResponse response){
        //do sume stuffs
         return "someView"; 
      }
    

    You want this GET because you are redirecting to it. Hence your solution will be

      @RequestMapping(value="/anotherUrl", method = { RequestMethod.POST, RequestMethod.GET })
          public String myAnotherFunc(HttpServletRequest request,HttpServletResponse response){
            //do sume stuffs
             return "someView"; 
          }
    

    Caution : here, if your method accepts some request parameters by @requestParam,then while redirecting you must pass them.

    Simply all attributes required by this method must send while redirecting...

    Thank You.

    0 讨论(0)
提交回复
热议问题