Get Query String Values in Spring MVC Controller

前端 未结 3 1528
Happy的楠姐
Happy的楠姐 2020-12-30 22:56

I have a referrer URL like this:

http://myUrl.com?page=thisPage&gotoUrl=https://yahoo.com?gotoPage

How do I get the Values of \"page\" and \"gotoUrl\" in

相关标签:
3条回答
  • 2020-12-30 23:11

    You can use the getParameter() method from the HttpServletRequest interface.

    For example;

      public void getMeThoseParams(HttpServletRequest request){
        String page = request.getParameter("page");
        String goToURL = request.getParameter("gotoUrl");
    }
    
    0 讨论(0)
  • 2020-12-30 23:24

    In SpringMVC you can specify values from the query string be parsed and passed in as method parameters with the @RequestParam annotation.

    public ModelAndView getPage(
        @RequestParam(value="page", required=false) String page, 
        @RequestParam(value="gotoUrl", required = false) String gotoUrl) {
    }
    
    0 讨论(0)
  • 2020-12-30 23:24

    Get the QueryString in Spring MVC Controller

    This is Liferay portal specific solution, and it works.

    Query String Example: ?reportTypeId=1&reportSeqNo=391

    In order to get the value of reportSeqNo in Liferay Portal, we need to get the Original Servlet Request.

    String reportSeq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getParameter("reportSeqNo");
    
    0 讨论(0)
提交回复
热议问题