2

I send following http request:

http://localhost:8081/member/createCompany/getSmallThumbnail/

On server side I hit into controller method:

@RequestMapping("/error")
public String error(Model model, HttpServletRequest request){
    if(request.getRequestURI().contains("thumbnail")){
        System.out.println("thumbnail accepted");
     }
     request.toString();
     model.addAttribute("message", "page not found");
     return "errorPage";
}

At this method I want to know url with which the request arrived.

If in debug I stop inside this method I see information needed for me: enter image description here

But I cannot find method in request which will return this.

Please help to return url which I want.

P.S.

Actually I have not mapped controller in my spring mvc application(url is broken) for http://localhost:8081/member/createCompany/getSmallThumbnail/. This url("/error") configured in web.xml as error page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • Your handler is mapped to `/error`, so the path would be `/error` (plus any path specified at your `@Controller`). – Sotirios Delimanolis Oct 02 '15 at 15:20
  • @Sotirios Delimanolis I understand it - but I need to get previous url. – gstackoverflow Oct 02 '15 at 15:21
  • What is _previous url_? I don't understand your question. The client sends a request, Spring determines the handler based on the path. If you're inside that handler, you know what that path is. – Sotirios Delimanolis Oct 02 '15 at 15:22
  • Possible duplicate of [What's the difference between getRequestURI and getPathInfo methods in HttpServletRequest?](http://stackoverflow.com/questions/4931323/whats-the-difference-between-getrequesturi-and-getpathinfo-methods-in-httpservl) – Joakim Erdfelt Oct 02 '15 at 15:25
  • @Sotirios Delimanolis I described my flow. I need to get **/member/createCompany/getSmallThumbnail/** please explain how can I achieve it ? – gstackoverflow Oct 02 '15 at 15:27
  • I didn't found answers in linked question – gstackoverflow Oct 02 '15 at 15:28
  • If your path is `/member/createCompany/getSmallThumbnail/`, then Spring would have invoked a handler method that's mapped to `/member/createCompany/getSmallThumbnail/`. That is static information. You already know that it's `/member/createCompany/getSmallThumbnail/`. Please clarify your question. – Sotirios Delimanolis Oct 02 '15 at 15:29
  • @Sotirios Delimanolis actually I have not controller method for http://localhost:8081/member/createCompany/getSmallThumbnail/ this url is broken thus I hit into this handler. It is configured in web.xml – gstackoverflow Oct 02 '15 at 15:31
  • Ok, that's a completely different question then. Please add that information into your question. It's an `` mapping. – Sotirios Delimanolis Oct 02 '15 at 15:33
  • @Sotirios Delimanolis topic update, thanks for correction – gstackoverflow Oct 02 '15 at 15:41

1 Answers1

9

Your request got redispatched to /error (presumably for error processing).

If this framework follows the normal Servlet error dispatching behavior, then your original request can be found in the HttpServletRequest.getAttributes() under the various javax.servlet.RequestDispatcher.ERROR_* keys.

  • ERROR_EXCEPTION - The exception object
  • ERROR_EXCEPTION_TYPE - The type of exception object
  • ERROR_MESSAGE - the exception message
  • ERROR_REQUEST_URI - the original request uri that caused the error dispatch
  • ERROR_SERVLET_NAME - the name of the servlet that caused the error
  • ERROR_STATUS_CODE - the response status code determined for this error dispatch

What you want is

String originalUri = (String) request.getAttribute(
                                       RequestDispatcher.ERROR_REQUEST_URI)
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136