Calling servlets


Web tier: servlets, JSP, Web frameworks: Calling servlets

  1. Calling servlets (1 messages)

    Hello! Is it possible to know where a servlet has been called from? I have a JSP which calls a servlet, and I would like to retrieve (inside the servlet´s code) the path for that JSP.
    Thanks in advance.

    Threaded Messages (1)

  2. Calling servlets[ Go to top ]

    With the interface HttpServletResponse you can use the method getRequestURL()to reconstruct the URL the client used to make the request.
    Therefore the code would look something like this:

    // ... inside your servlet class
    public void doGet(HttpServletRequest aRequest,
        HttpServletResponse aResponse)
            throws ServletException, IOException {
        PrintWriter out = aResponse.getWriter();
        out.println("You came from URL: " +
            aRequest.getRequestURL() + "<br>");
    // ... other methods used in your class