In spring mvc how to get the path to the path in the controller

I need the application context path in the controller, I tried the code below to throw NULLPOINTER EXCEPTION.

HttpServletRequest request,
String Path = request.getContextPath ();

Please help me
Thanks

+8
java spring controller
source share
1 answer
  • The request variable is declared, but not initialized. No wonder you get a NullPointerException .

  • See the documentation for access to various query related data.

After you read this and make sure you want to bind your code to the Servlet native API, try the following:

 @Controller class MyController { @RequestMapping public void handleMe(HttpServletRequest request) { String path = request.getContextPath(); } } 
+19
source share

All Articles