springmvc学习笔记(一)第一个helloworld

1.新建web工程,导入spring包和common-loggin.jar包;配置web.xml




      
        springMVC  
        org.springframework.web.servlet.DispatcherServlet  
        1  
      
      
        springMVC  
        /  
      

2.编写Controller类,相当于struts2中的Action

public class HelloWorldController implements Controller{

	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		System.out.println("8888888888888888888");
		return new ModelAndView("welcome");
	}

}

返回结果是以welcome为参数的,意思是跳转到welcome.jsp显示视图.

3.配置"servletName"-servlet.xml

-servlet.xml文件名称默认根据web.xml中配置的DispacherServlet的servlet名称,加上-servlet.xml而来的.

所以当前的配置文件名称为 springMVC-servlet.xml.


 
    
      
      
          
        
      
   

id为/test1/helloWorld的bean的类对应上面的controller.

4.视图jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>



  
    My JSP 'welcom.jsp' starting page
    
  
  
  
    欢迎大家来学习springmvc


5.测试.


浏览器中输入controller的id

http://localhost:8080/springMVC/test1/helloWorld


你可能感兴趣的:(springmvc)