SpringMVC
第一个简单案例:
1) 建一个Web工程
2) 在web.xml中配置
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3) 在web-inf下建一个springMVC-servlet.xml文件,配置:
<beanid="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<propertyname="prefix"value="/"></property>
<propertyname="suffix"value=".jsp"></property>
</bean>
4) 建一个HelloController并且继承Controller的class
packagecontroller;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importorg.springframework.web.servlet.ModelAndView;
importorg.springframework.web.servlet.mvc.Controller;
publicclass HelloController implements Controller {
public ModelAndViewhandleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception{
System.out.println("hello this is firsttest");
return new ModelAndView("hello");
}
}
5) 然后springMVC-servlet.xml中配置
<beanname="/test/hello"class="controller.HelloController"></bean>
6) 编写hello.jsp页面
最后就可以启动Tomcat,通过项目名加上test/hello访问Hellocontroller并且跳转到helo.jsp
原文地址:http://blog.csdn.net/u013516966/article/details/39511563