주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
꽃배달 한국, 중국 전지역배송

Spring 기초

hmily1129 | 2013.08.05 08:10:13 댓글: 0 조회: 2092 추천: 0
분류웹 프로그래밍 https://life.moyiza.kr/itstudy/2001787

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를 호출하고 데이터를 받는다.


추천 (0) 선물 (0명)
IP: ♡.118.♡.4
3,006 개의 글이 있습니다.
제목 글쓴이 날짜 조회
관리자
2003-09-20
11711
관리자
2003-09-20
11254
관리자
2003-09-20
20317
지구인
2010-08-27
19181
지구인
2009-09-07
13466
SOLIDH
2010-01-29
15461
엔죠라이프
2004-10-07
16568
CHOSUN
2014-01-11
2441
CHOSUN
2014-01-07
2596
CHOSUN
2014-01-07
2381
CHOSUN
2014-01-07
2050
CHOSUN
2014-01-07
1792
CHOSUN
2014-01-07
1612
CHOSUN
2014-01-07
1177
즐거운개굴
2013-09-29
3002
hmily1129
2013-09-03
4910
hmily1129
2013-08-29
5364
hmily1129
2013-08-26
4793
hmily1129
2013-08-25
3635
hmily1129
2013-08-24
4165
hmily1129
2013-08-23
4323
hmily1129
2013-08-23
3597
hmily1129
2013-08-22
1888
hmily1129
2013-08-10
1623
hmily1129
2013-08-05
2152
hmily1129
2013-08-05
2092
hmily1129
2013-07-30
1470
CHOSUN
2013-07-23
1942
모이자 모바일