spring mvc - URL pattern servlet mapping -
i created hello world example using spring mvc, there 1 thing didn't understand in servlet url mapping, did following in web.xml:
<servlet> <servlet-name>helloweb</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>helloweb</servlet-name> <url-pattern>/test/*</url-pattern> </servlet-mapping>
now if want call following controller:
@controller @requestmapping("/hello") public class helloworld { @requestmapping(method = requestmethod.get) public string printwelcome(modelmap model){ model.addattribute("message","hello world"); return "index"; } }
it work using following link: http://localhost:8080/test/hello
but when change servlet url-pattern "/*" , try: http://localhost:8080/hello
it doesn't work, shouldn't match servlet ? * matches everything
when register servlet "/*" override servlet mappings if there any. hence should avoided. overrides default servlet mapping hence default url handling overridden , hence specific url matching fails. in case /hello.
with case, registered /test/* registered url's /test , hence got identified.
Comments
Post a Comment