这里是简单的代码,当它与 url 匹配时调用 amazon.java 休息类作为
http://anydomain.com/amazone如果你在 url 中点击它而不是它调用的 get 方法
public class RestApi extends Application {
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
// Defines only one route
router.attach("/amazon", Amazon.class);
return router;
}
}
亚马逊.java
public class Amazon extends ServerResource {
@Override
protected Representation post(Representation entity)
throws ResourceException {
System.out.println("post Method");
return super.post(entity);
}
@Override
protected Representation get() throws ResourceException {
System.out.println("get method");
return super.get();
}
}
并将 web.xml 文件中的映射为
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.wa.gwtamazon.server.RestApi </param-value>
</init-param>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>