My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
SpringSetup  
Spring Setup used in the application
Updated Sep 8, 2009 by umam...@gmail.com

If web.xml has the following declaration, it means that all uris that end with .html (ex: http://localhost:8080/stockapp/mytest.html}, will use the file springapp-servlet.xml to find a corresponding mapping. Other Uris (ex: http://localhost:8080/stockapp/index.jsp will not use spring mapping}

	<servlet-mapping> 
		<servlet-name>springapp</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>

The file springapp-servlet.xml is located in the WEB-INF directory and looks like this:

<beans>
	<!-- This should have a map for redirects -->
	<bean id="springappController" class="com.stockapp.controller.SpringappController" />
	
	<bean id="urlMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<props>
				<prop key="/home.html">springappController</prop>
			</props>
		</property>
	</bean>
	
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass">
			<value>org.springframework.web.servlet.view.JstlView</value>
		</property>
		<property name="prefix">
			<value>/jsp/</value>
		</property>
		<property name="suffix">
			<value>.jsp</value>
		</property>
	</bean>	
</beans>

In the above, we define a simple controller class called SpringappController.

We then map the uri /home.html to this controller. So all http requests that end with home.html will be routed through this controller.

We also use a Spring MVC View Resolver to indicate that all Jsps will sit in a directory called jsp and will have an extension .jsp.

Powered by Google Project Hosting