java - Unused URI template variable - can I replace it with a wildcard? -
i have code along following lines in spring mvc webapp:
@requestmapping("/{somevariable}/apath/apage.do") public void serveapage() { dostuff(); }
we want "somevariable" in url, aren't interested in capturing , using value of it. there way of replacing wildcard, e.g. /*/apath/apage.do
?
yes, @requestmapping accepts ant-style patterns http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/requestmapping.html#params()
so works:
@requestmapping(value="/*/test2.do") public void getmeta5(httpservletrequest request, httpservletresponse response) throws ioexception { final printwriter writer = response.getwriter(); writer.print("requesturi:" + request.getrequesturi()); writer.flush(); }
this assumes servlet-mapping in web.xml maps url path dispatcherservlet, e.g.
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
Comments
Post a Comment