A default servlet mapping has a mapping of only the / character. In previous versions of WebSphere,
a call to the javax.servlet.http.HttpServletRequest.getServletPath method for a default servlet mapping
returns an empty string, and a call to the javax.servlet.http.HttpServletRequest.getPathInfo method
returns the / character.
However, in Liberty with the Servlet 4.0 feature, a call to getServletPath for a default servlet mapping
will return the / character and a call to getPathInfo will return null.
For example, consider the following code:
|
@WebServlet("/") public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) { System.out.println("getServletPath: " + req.getServletPath()); System.out.println("getPathInfo: " + req.getPathInfo()); } } |
In WebSphere traditional and Liberty with Servlet 3.0 or 3.1, the code will have the following output:
|
getServletPath: getPathInfo: / |
In Liberty with Servlet 4.0, the code will have the following output:
|
getServletPath: / getPathInfo: null |
To return to the previous behavior when using the Servlet 4.0 feature, add the following configuration to the
server.xml file: <webContainer servletPathForDefaultMapping="false"/>
For additional information, see: