java - In spring mvc how to get the context path in controller -


i need application context path in controller, tried below code throwing nullpointer exception.

httpservletrequest request;
string path = request.getcontextpath();

please me
thanks

  1. variable request declared, not initialized. no wonder nullpointerexception.

  2. look @ documentation access different request related data.

after read that, , sure want tie code native servlet api, try this:

@controller class mycontroller {      @requestmapping     public void handleme(httpservletrequest request) {         string path = request.getcontextpath();     } } 

Comments