Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

Generic Top

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:


1. Overview

In this quick tutorial, we'll discuss the difference between getRequestURI() and getPathInfo() in the HttpServletRequest class.

2. Difference Between getRequestURI() and getPathInfo()

The function getRequestURI() returns the complete requested URI. This includes the deployment folder and servlet-mapping string. It will also return all extra path information.

The function getPathInfo() only returns the path passed to the servlet. If there is no extra path information passed, this function will return null.

In other words, if we deploy our application in our web server's root, and we request the servlet mapped to “/”, both getRequestURI() and getPathInfo() will return the same string. Otherwise, we'll get different values.

3. Example Request

In order to get a better understanding of the HttpServletRequest methods, let's say we have a servlet which can be accessed via this URL:


This request will hit the “servlet-mapping” servlet in a web application deployed inside “deploy-folder”. Therefore, if we call getRequestURI() and getPathInfo() for this request, they will return different strings.

Let's create a simple doGet() servlet method:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    PrintWriter writer = response.getWriter();
    if ("getPathInfo".equals(request.getParameter("function")) {
    } else if ("getRequestURI".equals(request.getParameter("function")) {

Firstly, let's take a look at the output of the servlet for getRequestURI requests fetched by curl command:

curl http://localhost:8080/deploy-folder/servlet-mapping/request-path?function=getRequestURI

Similarly, let's take a look at the output of the servlet for getPathInfo:

curl http://localhost:8080/deploy-folder/servlet-mapping/request-path?function=getPathInfo

4. Conclusion

In this article, we've explained the difference between getRequestURI() and getPathInfo() in HttpServletRequest. We also demonstrated it with an example servlet and request.

As always, the servlet implemented to test all these functions is available over on Github.

Generic bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

Generic footer banner
Comments are closed on this article!