Java HttpServletRequest get URL in browsers URL bar

后端 未结 7 677
旧巷少年郎
旧巷少年郎 2020-11-27 14:03

So I\'m trying to grab the current URL of the page using Java\'s request object. I\'ve been using request.getRequestURI() to preform this, but I noticed that when a java cla

7条回答
  •  粉色の甜心
    2020-11-27 15:04

    Same answer as @kdgregory, but you can rather use the Request Dispatcher constants.

    javax.servlet.include.request_uri        RequestDispatcher.FORWARD_REQUEST_URI
    javax.servlet.include.context_path       RequestDispatcher.FORWARD_CONTEXT_PATH
    javax.servlet.include.servlet_path       RequestDispatcher.FORWARD_SERVLET_PATH
    javax.servlet.include.path_info          RequestDispatcher.FORWARD_PATH_INFO
    javax.servlet.include.query_string       RequestDispatcher.FORWARD_QUERY_STRING
    

提交回复
热议问题