Reputation: 373
I need application context path in controller, I tried the below code its throwing NULLPOINTER EXCEPTION.
HttpServletRequest request;
String Path = request.getContextPath();
Please help me
Thanks
Upvotes: 13
Views: 46310
Reputation: 6821
Variable request
is declared, but is not
initialized. No wonder you get a NullPointerException
.
Look at documentation to access different request related data.
After you read that, and are sure you want to tie your code to native Servlet API, try this:
@Controller
class MyController {
@RequestMapping
public void handleMe(HttpServletRequest request) {
String path = request.getContextPath();
}
}
Upvotes: 31