java - How to get local mapping of a servlet in its init method? -


i've servlet , it's init method must http calls itself. because i'm using embedded app, starts , it's main interface it's restful api. can't , don't want use internal classes, because not documented , difficult use. prefere use rest api through local http.

so, extended servlet comes app , modified init method, starts thread , http calls itself. moment hardwired "http://localhost:port/servlet/mapping/" path, i'd have dynamic @ least detect port number , mapping too.

is there decent way this? found lots of examples extract information httpservletrequest object, in init method don't have it. have servletcontext.

ah, way, use servlet api 3.0.

in servlets 3 can current mappings given servlet:

string servletname = servletconfig.getservletname(); servletregistration reg = servletconfig.getservletcontext().getservletregistration(servletname); for(string mapping: reg.getmappings()) {     // mapping } 

about port number, given fact servlet container can "listening" on more 1 port, there no standard way can know port number if there one.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -