Simple Spring URL Handling?
I am using Spring MVC for an application I am building. Everything is working fine, but what I do not know how to do is a simple link with Spring. Currently, I have everything mapped with a *.htm to a controller. This all works fine be开发者_如何转开发cause they have controllers to handle them.
What I am not sure how to do is a simple link where there is an anchor tag that has a .jsp link, and it just goes to that page, and needs no form processing.
I know this is a very basic question, but I just want to know the easiest way to configure this.
And if this is not possible, and all links must go through a controller, I would like to know.
Thank you.
First thing you need to do is make sure you don't have a Spring DispatcherServlet mapped to the root of the application context. e.g., if your Dispatcher is mapped to /*
change it to /pages/*
or something. A dispatcher sitting on the root will "eat" any requests for regular resources. (Alternately you could customize it to pass through for static resources, but that's I think beyond the scope of the question.) Then if you just put a jsp file in your webapp/whatever
folder (not /WEB-INF
, the level above it.) You should be able to navigate to it normally.
/webapp/whatever/index.jsp
/webapp/WEB-INF/dispatcher-servlet.xml
web.xml :
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/pages/*</url-pattern>
</servlet-mapping>
Should result in being able to go to http://soisawesome.com/app/whatever/index.jsp
as well as /pages/controllerhandledform.htm
精彩评论