note

@RequestHeader 어노테이션을 이용한 헤더 매핑 본문

JSP/Spring

@RequestHeader 어노테이션을 이용한 헤더 매핑

투한 2012. 3. 5. 11:21









dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">


	<!-- @RequestHeader 어노테이션을 이용한 헤더 매핑 -->
	<bean class="madvirus.spring.chap06.controller.HeaderController" />
	
	<!-- View 글로벌 설정 -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/view/" />
		<property name="suffix" value=".jsp" />
	</bean>
</beans>





id를 입력하지 않아도 HeaderController 에서 HeaderController를 headerController로 바꿔서 인식해줌







HeaderController.java
package madvirus.spring.chap06.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HeaderController {

	//@RequestHeader 어노테이션은 클라이언트가 전송한 헤더 정보 읽기
	
	@RequestMapping("/header/check.do")
	public String check(@RequestHeader("Accept-Language")String languageHeader){

		System.out.println(languageHeader);

		return "header/pass";
	}
}




@RequestHeader 어노테이션은 클라이언트가 전송한 헤더 정보 읽기






header/pass.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>헤더 검사 통과</title>
</head>
<body>
헤더 검사 통과
</body>
</html>