0

I'm using mediator design pattern for my web project. There is a front controller to take care all requests, and base on each request to find suitable servlet. In web.xml, I try this:

<servlet-mapping>
         <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/*</url-pattern>
</servlet-mapping>

And then a request like localhost:8080/project_name/a/b/c/d.jsp I want to get the string a/b/c/d.jsp but when I use: request.getServletPath() I get empty string.

Thanks :)

0

1 Answer 1

5

You should use getPathInfo() method instead

getServletPath() method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.

getPathInfo() method returns path information follows the servlet path but precedes the query string and will start with a "/" character.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.