Where The Streets Have No Name

spring mvc에서 interceptor적용 본문

Developement/Java

spring mvc에서 interceptor적용

highheat 2011. 10. 21. 17:48
@RequestMapping(value = "/test/Test3Json.do")
public ModelAndView test3json(@RequestParam(value="name", required=false) String name) {
	JSONObject obj=new JSONObject();
	obj.put("name","홍길동");
	obj.put("num",new Integer(100));
	obj.put("balance",new Double(1000.21));
	obj.put("is_vip",new Boolean(true));
	obj.put("nickname",null);
		
	ModelAndView model = new ModelAndView(new JsonView());
	model.addObject(obj.toJSONString());
	return model;
}
package egovframework.rte.test.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AuthInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println("@@@@@@@@@@@@@@@@@@@@@@");
		return true;
	}	
}

dispatcher-servlet.xml

<bean id="authenticInterceptor" class="egovframework.rte.test.web.AuthInterceptor" />
    
<bean id="selectAnnotaionMapper"
	class="egovframework.rte.ptl.mvc.handler.SimpleUrlAnnotationHandlerMapping"
	p:order="1">
	<property name="interceptors">
		<list>
			<ref local="authenticInterceptor" />
		</list>
	</property>
	<property name="urls">
		<set>
			<value>/test/*.do</value>
		</set>
	</property>
</bean>