상세 컨텐츠

본문 제목

[GWT] server side 의 url mapping

소프트웨어/java

by 야솔아빠 2011. 12. 1. 19:01

본문

반응형

Include the server-side code in the GWT module

The embedded servlet container (Jetty) can host the servlets that contain your service implementation. This means you can take advantage of running your application in development mode while testing and debugging the server-side Java code.

To set this up, add <servlet> and <servlet-mapping> elements to the web application deployment descriptor (web.xml) and point to the implementation class (StockPriceServiceImpl).

Starting with GWT 1.6, servlets should be defined in the web application deployment descriptor (web.xml) instead of the GWT module (StockWatcher.gwt.xml).

In the <servlet-mapping> element, the url-pattern can be in the form of an absolute directory path (for example, /spellcheck or /common/login). If you specify a default service path with a @RemoteServiceRelativePath annotation on the service interface (as you did with StockPriceService), then make sure the url-pattern matches the annotation value. Because you've mapped the StockPriceService to "stockPrices" and the module rename-to attribute in StockWatcher.gwt.xml is "stockwatcher", the full URL will be:
http://localhost:8888/stockwatcher/stockPrices

  1. Edit the web application deployment descriptor (StockWatcher/war/WEB-INF/web.xml).
    Since the greetServlet is no longer needed, its definition can be removed.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
    
      <!-- Default page to serve -->
      <welcome-file-list>
        <welcome-file>StockWatcher.html</welcome-file>
      </welcome-file-list>
    
      <!-- Servlets -->
      <servlet>
        <servlet-name>stockPriceServiceImpl</servlet-name>
        <servlet-class>com.google.gwt.sample.stockwatcher.server.StockPriceServiceImpl</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>stockPriceServiceImpl</servlet-name>
        <url-pattern>/stockwatcher/stockPrices</url-pattern>
      </servlet-mapping>
    
    </web-app>
    

튜토리얼 문서에는 http://localhost:8888/stockwatcher/stockPrices 이렇게 매핑된다고 한다.
즉 StockWatcher.gwt.xml의 "<module rename-to='stockwatcher'>"
부분이 context root 가 되는 것 같다.

이 구조를 잘 이해하면 spring으로 서버단을 구성할 수 있을 것 같다.

이해가 안되면, StockPriceService.java 의 annotation을 다른 것으로 해서 테스트 해보면 404 에러가 난다.
package com.google.gwt.sample.stockwatcher.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("stockPrices1")
public interface StockPriceService extends RemoteService {

  StockPrice[] getPrices(String[] symbols) throws DelistedException;
}

반응형

'소프트웨어 > java' 카테고리의 다른 글

주(week)로 부터 날짜 리턴  (0) 2012.10.25
GC 분석을 위한 Heap Dump 생성 option  (0) 2012.02.15
Java HeapDump 생성하는 옵션  (0) 2011.12.08
[Java thread] run()에 data 전달하기.  (0) 2011.11.28
JarClassFinder  (0) 2011.11.08

관련글 더보기

댓글 영역