当前位置 : 主页 > 编程语言 > c++ >

SpringMVC的注解(1)

来源:互联网 收集:自由互联 发布时间:2021-07-03
@Controller将目标类标识为一个请求处理器,@RequestMapping映射请求 import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class HelloWorld {private s
@Controller将目标类标识为一个请求处理器,@RequestMapping映射请求
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloWorld {

	private static String success="success";
	
	@RequestMapping("/helloworld")
	public String hello() {
		System.out.println("Hello World");
		return success;
	}
}
web.xml配置文件
 

 
  
  
  
	
   
   
    springDispatcherServlet
    
   
    org.springframework.web.servlet.DispatcherServlet
    
    
    
     contextConfigLocation
     
    
     classpath:springmvc.xml
     
    
   
    1
    
  

	
  
	
   
   
    springDispatcherServlet
    
   
    /
    
  
	
	
  
	
   
   
    HiddenHttpMethodFilter
    
   
    org.springframework.web.filter.HiddenHttpMethodFilter
    
  
	
	
   
   
    HiddenHttpMethodFilter
    
   
    /*
    
  
  

 
springmvc.xml配置文件
 

 

	
  

	
   
    
    
  

 
请求页面index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="ISO-8859-1"%>
	
	

	
		
 
		Insert title here
	

	

		Hello World
testParamAndHeader
testAntPath
testPathVariable
Test Get
返回的成功页面success.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="ISO-8859-1"%>




 
Insert title here



Success

ModelAndView: ${requestScope.studentMsg } Map: ${requestScope.users } Map: ${requestScope.xixi } SessionAttributes: ${sessionScope.user } SessionAttributes: ${sessionScope.msg }
网友评论