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

Spring 기초

hmily1129 | 2013.08.05 08:10:13 댓글: 0 조회: 2095 추천: 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
11733
관리자
2003-09-20
11276
관리자
2003-09-20
20339
지구인
2010-08-27
19201
지구인
2009-09-07
13494
SOLIDH
2010-01-29
15482
엔죠라이프
2004-10-07
16592
CHOSUN
2014-01-11
2442
CHOSUN
2014-01-07
2598
CHOSUN
2014-01-07
2384
CHOSUN
2014-01-07
2052
CHOSUN
2014-01-07
1794
CHOSUN
2014-01-07
1613
CHOSUN
2014-01-07
1179
즐거운개굴
2013-09-29
3003
hmily1129
2013-09-03
4911
hmily1129
2013-08-29
5372
hmily1129
2013-08-26
4794
hmily1129
2013-08-25
3638
hmily1129
2013-08-24
4167
hmily1129
2013-08-23
4324
hmily1129
2013-08-23
3598
hmily1129
2013-08-22
1892
hmily1129
2013-08-10
1626
hmily1129
2013-08-05
2155
hmily1129
2013-08-05
2095
hmily1129
2013-07-30
1472
CHOSUN
2013-07-23
1945
모이자 모바일