How do you detect the URL in a Java Servlet when forwarding to JSP?

前端 未结 2 1076
难免孤独
难免孤独 2021-01-06 12:53

I have a servlet that looks something like this:

public class ExampleServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServ         


        
2条回答
  •  清酒与你
    2021-01-06 13:47

    The URL the user (browser) requested can be accessed from the request by:

    request.getRequestURL()
    

    Alternatively the request has a whole bunch of accessors to get the various pieces of the URL as well as those on ServletRequest.

    To redirect to a different URL change the response rather than the request:

    response.sendRedirect(theURLToRedirectTo)
    

提交回复
热议问题