jetty - Redirecting root context path or binding it to a servlet or mapping it with a welcome-file -
i using jetty-9 in embedded mode , need 1 web application. consequently root url go homepage of application, i.e. like
http://localhost:4444/
should end in servlet. start out with:
servletcontexthandler sccontext = new servletcontexthandler(servletcontexthandler.sessions); sccontext.setcontextpath("/");
none of next worked, neither
sccontext.addservlet(listsservlet.class, "/");
nor
sccontext.setwelcomefiles(new string[]{"/lists})
where /lists
mapped listsservlet
servlet. 403 (forbidden).
i not utilize defaultservlet
, seems handle welcome files. since servletcontexthandler
has setwelcomefiles
expected contain logic utilize them.
any ideas?
for 403 forbidden
error, have security setup not allowing access handlers/servlets.
eliminate security (for now), verify rest working, add together security bit later lock downwards specifics.
if want see suggestions below @ work, consider looking @ code illustration in reply stackoverflow: how correctly back upwards html5 <video> sources jetty.
welcome files appended incoming request path if there nil nowadays @ location. illustration requesting directory , welcome-file of 'index.html' appended request path.
while work ...
class="lang-java prettyprint-override">sccontext.setwelcomefiles(new string[]{"lists"}) // add together default servlet (must named "default") servletholder holderdefault = new servletholder("default",defaultservlet.class); holderdefault.setinitparameter("resourcebase",basedir.getabsolutepath()); holderdefault.setinitparameter("dirallowed","true"); holderdefault.setinitparameter("welcomeservlets","true"); holderdefault.setinitparameter("redirectwelcome","true"); sccontext.addservlet(holderdefault,"/");
it's not aiming for, said root path only. above create changes requests /foo/
/foo/lists
instead, might create more sense utilize rewrite rule + handler instead of welcome-files approach.
class="lang-java prettyprint-override">rewritehandler rewrite = new rewritehandler(); rewrite.sethandler(sccontext); rewritepatternrule rootrule = new rewritepatternrule(); rootrule.setpattern("/"); rootrule.setreplacement("/list"); rootrule.setterminating(true); rewrite.addrule(rootrule); server.sethandler(rewrite);
this rewritepatternrule
changes request path /
/list
, forwards request wrapped sscontext
(if want see /list
on browser, alter redirectpatternrule
instead.
jetty embedded-jetty jetty-9 welcome-file
No comments:
Post a Comment