DWR 1.x 에서는 설정파일인 dwr.xml이 꼭 필요하다. DWR 2.x에서는 기존방법과 함께 Spring 설정파일로 dwr.xml을 대신 할수 있다.
설정 순서를 보자.
1. web.xml
[DWR 1.x 기존설정]
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
[DWR 2.x 신규설정]
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
기존에 사용하는 DWRServlet을 DwrSpringServlet으로 사용하는 점이 다른 것이다.
이것은 ContextLoaderListener에서 읽어 들인다.
만약 SpringMVC를 사용한다면,
위 설정 마져도 생략하고, Controller 설정파일에서 <dwr>Tag를 이용해서 설정 가능하다.
ex) <dwr:controller id="ajaxCommentController" debug="true"/>
2. beans-comment-service.xml
일반적인 Bean 설정파일이다. 보통은 applicationContext.xml라는 명으로 많이 사용한다.
<?xml version="1.0" encoding="UTF-8"?>
<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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">
<description>comment-service</description>
<bean id="commentRepository" class="net.max.comment.domain.jdbc.JdbcCommentRepositoryImpl"
p:dataSource-ref="dataSource"
p:oracleLobHandler-ref="oracleLobHandler"/>
<bean id="commentService" class="net.max.comment.domain.CommentServiceImpl">
<dwr:remote javascript="AjaxCommentService"/>
<property name="commentRepository" ref="commentRepository"></property>
</bean>
</beans>
<dwr> Tag를 사용하기 위해서 Spring DTD를 선언해 주고, Ajax로 서비스할 원하는 Bean에
<dwr> Tag를 넣는다.
이때, SpringIDE의 자동완성 기능이 속성에 관한 도움말을 준다.
설정이 끝났다. 기존 방법보다 월등히 간단해 졌고, 관리도 편해 진다.
3. 테스트 페이지
getComment( "test",939 ,262); 실행시 결과
4. 참고자료
http://bram.jteam.nl/index.php/2007/01/31/spring-dwr-ajax-made-easy/
http://getahead.org/dwr/server/spring
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 81 | [React.JS] 강좌 목록 | 황제낙엽 | 2020.05.19 | 385 |
| 80 |
Redux: React 앱의 효율적인 데이터 교류
| 황제낙엽 | 2020.05.19 | 971 |
| 79 | Jasmine 관련 | 황제낙엽 | 2020.01.13 | 492 |
| 78 | 마우스 드래그(drag)시 iframe 위에서 컨트롤 잃는 현상과 해결 방안 | 황제낙엽 | 2017.12.12 | 28271 |
| 77 | 다섯 가지의 Ajax 우수 사례 | 황제낙엽 | 2011.04.07 | 490 |
| 76 | 15+ jQuery Popup Modal Dialog Plugins and Tutorials | 황제낙엽 | 2011.03.30 | 574 |
| 75 |
$.ajax() 공략
| 황제낙엽 | 2011.03.27 | 670 |
| 74 | DWR을 이용해서 객체를 JSON으로 변환하기 | 황제낙엽 | 2011.03.25 | 347 |
| 73 |
json을 이용한 로그인 구현
| 황제낙엽 | 2011.03.25 | 832 |
| 72 | How Prototype extends the DOM (Prototype으로 DOM을 확장하는 법) | 황제낙엽 | 2011.03.24 | 695 |
| 71 | 스크랩 | 황제낙엽 | 2009.04.16 | 439 |
| 70 | YUI 스크랩 | 황제낙엽 | 2009.03.12 | 323 |
| 69 | 스크랩 | 황제낙엽 | 2009.03.11 | 316 |
| 68 | 관심 사이트 | 황제낙엽 | 2009.03.12 | 431 |
| 67 | 웹 개발 패러다임의 전환 - Flex와 Ajax의 동거 | 황제낙엽 | 2006.12.21 | 434 |
| 66 | Ajax 강의 정리 | 황제낙엽 | 2006.04.04 | 387 |
| 65 | 자바 기술을 이용한 AJAX의 활용 | 황제낙엽 | 2006.02.08 | 347 |
| 64 |
대표적인 AJAX Framework 소개
| 황제낙엽 | 2007.02.14 | 414 |
| 63 | Ajax Framework 인기 순위: Ajaxian.com | 황제낙엽 | 2007.02.13 | 368 |
| 62 |
prototype.js 를 위한 개발자 노트 (Ajax Framework)
| 황제낙엽 | 2007.02.15 | 335 |