1 . web.xml 설정
<servlet>
<servlet-name>eLab</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>eLab</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
설명 : client에서 들어오는 *.do형식의 호출은 DispatcherServletet가 받아서 처리한다.
2. *-servlet.xml 설정
파일의 경로를 지정해 주지 않으면 spring은 기본으로 web-info 밑에 *.servlet파일을 찾아간다.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.eLab.Services" />
</beans>
설명 : <context:component-scan base-package="com.eLab.Services" /> 은 http://www.springframework.org/schema/context로 com.eLab.Services의 밑에 주석을 해석한다.
3. 컨트롤러
package com.eLab.Services;
@Controller
public class eLabController {
@RequestMapping(value = "/hello.do", method = RequestMethod.POST)
public @ResponseBody
String hello(@ModelAttribute(value = "user") User user,
BindingResult result,HttpSession session) {
String returnText;
if (!result.hasErrors()) {
returnText ="성공";
} else {
returnText = "실패";
}
return returnText;
}
}
설명 : @Controller,@RequestMapping,@ModelAttribute를 자동으로 해석된다.
4. ajax 호출
jQuery(function($) {
$.ajax({
type : "POST",
url : "hello.do",
data : {}
}).done(function(msg) {
alert(msg);
});
});
설명 : 위에서 해석된 controller hello.do를 호출하고 데이터를 받는다.
제목 | 글쓴이 | 날짜 | 조회 |
---|---|---|---|
2003-09-20 |
11760 |
||
2003-09-20 |
11294 |
||
2003-09-20 |
20367 |
||
지구인 |
2010-08-27 |
19224 |
|
지구인 |
2009-09-07 |
13525 |
|
2010-01-29 |
15501 |
||
2004-10-07 |
16613 |
||
2014-01-11 |
2444 |
||
2014-01-07 |
2600 |
||
2014-01-07 |
2387 |
||
2014-01-07 |
2053 |
||
2960 [공개소스] 그누보드 4.36.27 |
2014-01-07 |
1795 |
|
2959 [공개소스] 그누보드 4.36.26 |
2014-01-07 |
1615 |
|
2958 [공개소스] 그누보드 4.36.25 |
2014-01-07 |
1181 |
|
즐거운개굴 |
2013-09-29 |
3003 |
|
2013-09-03 |
4913 |
||
2955 [웹 프로그래밍] ajax 특수문자 |
2013-08-29 |
5372 |
|
2013-08-26 |
4795 |
||
2013-08-25 |
3639 |
||
2013-08-24 |
4169 |
||
2013-08-23 |
4325 |
||
2013-08-23 |
3601 |
||
2013-08-22 |
1893 |
||
2948 [웹 프로그래밍] log4j |
2013-08-10 |
1627 |
|
2013-08-05 |
2156 |
||
2013-08-05 |
2096 |
||
2013-07-30 |
1472 |
||
2013-07-23 |
1945 |