开始学习springMVC
首先下载springMVCjar包
在web.xml里注册servlet
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>*.abc</url-pattern>
</servlet-mapping>
然后根据web.xml文件里的<servlet-name>test</servlet-name>名字创建test-servlet.xml文件
springMVC主要有DispatcherServlet ----->controller----->modelandview
实例代码:
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="test.abc">startController</prop>
<prop key="add.abc">addController</prop>
<prop key="addEmp.abc">addEmpController</prop>
</props>
</property>
</bean>
<bean id="startController" class="cxd.test.MyController"></bean>
<bean id="addController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"></bean>
<bean id="addEmpController" class="cxd.test.addEmpController">
<property name="commandClass" value="cxd.test.Emp"></property>
</bean>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
org.springframework.web.portlet.mvc
Class ParameterizableViewController
void |
setViewName(String viewName) Set the name of the view to delegate to. |
org.springframework.web.servlet.mvc
Class UrlFilenameViewController
比上面的更简单,它是根据urlfilename来转发到下一个view,比如login.test--->login.jsp不需要配置其它参数