java spring URL mapping -
i using maven web application, framework spring.
using netbeans ide , tomcat server.
when run web in netbeans, url in browser is:
http://localhost:8080/mywebsite
with url website cannot read event servlet mapping.
when change url http://localhost:8080/mywebsite/ run good.
what reason case? why website don't auto add character "/" in url?
{update}
config.java
public class config extends webmvcconfigureradapter {
@bean public urlbasedviewresolver setupviewresolver() { urlbasedviewresolver resolver = new urlbasedviewresolver(); resolver.setprefix("/web-inf/html/"); resolver.setsuffix(".jsp"); resolver.setviewclass(jstlview.class); return resolver; } @override public void addresourcehandlers(resourcehandlerregistry registry) { registry.addresourcehandler("/resources/**").addresourcelocations("/web-inf/resources/*"); } }
initializer
@override public void onstartup(servletcontext servletcontext) throws servletexception { annotationconfigwebapplicationcontext ctx = new annotationconfigwebapplicationcontext(); ctx.register(config.class); ctx.setservletcontext(servletcontext); servletregistration.dynamic servlet = servletcontext.addservlet("dispatcher", new dispatcherservlet(ctx)); servlet.addmapping("/"); servlet.setloadonstartup(1); }
controller
@controller public class mycontroller { //<editor-fold defaultstate="collapsed" desc="admin"> @requestmapping(value = "/", method = requestmethod.get) public string login(modelmap map) { return "admin/login"; }}
if open http://localhost:8080/mywebsite
, web app try find index.html
file(based on tomcat or http server configuration).
and mapping @requestmapping(value = "/", method = requestmethod.get)
, apply http://localhost:8080/mywebsite/
. if want use controller handle http://localhost:8080/mywebsite
, can try use *
in mapping value. means, request, if there no specific mapping defined, , default mapping applied.
Comments
Post a Comment