第一,就是引入依赖jar包。
第二,编写一个web工程
在用到SpringMvc的话我们不在编写servlet这个文件了
1.编写一个类
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FirstController implements Controller { public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView ma = new ModelAndView(); ma.setViewName("/index.jsp"); return ma; } }
2,在springxml中添加这样一行bean节点
<bean id="/xxx" class="cn.mvc.dome1.FirstController"></bean>
3,在web.xml中编写代码
<servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
4,通过测试我们可以不用servlet就可以响应jsp动态页面
结束....