首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Restlet 2.0 - 启动

2012-10-07 
Restlet 2.0 - 起步目录这篇文章将带领您花10分钟的时间品尝一个简单的Restlet框架搭建过程,它将向你展示

Restlet 2.0 - 起步
目录
这篇文章将带领您花10分钟的时间品尝一个简单的Restlet框架搭建过程,它将向你展示一个经典的"hello, world"资源。
前提条件"hello, world"应用程序在Servlet容器中运行作为独立的Java应用程序运行总结
1、前提
我们假设您有一定的java基础知识,并且已经搭建了基于JRE1.5或更高版本的Java运行环境,如果您尚未下载Restlet2.0或更高版,请前往http://www.restlet.org/downloads 下载。

2、"hello, world"应用程序
Restlet应用的核心是“资源”(Resource)。下面我们创建“资源”:HelloWorldResource.class,代码如下:


【提示:需要加入org.restlet.jar和javax.servlet.jar】
您可以将项目打包为firstStepsServlet.war并且部署在您的Servlet容器里运行,打开浏览器,输入:http://<your server name>:<its port number>/firstStepsServlet/hello,不出意外的话,将会呈现"hello, world"。


4、作为独立的Java应用程序运行
Restlet框架允许作为独立的Java应用程序运行,仅需要用到org.restlet.jar即可实现。在FistStepsApplication中新建一个方法,代码如下:
public static void main(String[] args) {       try {           // Create a new Component.           Component component = new Component();             // Add a new HTTP server listening on port 8182.           component.getServers().add(Protocol.HTTP, 8182);             // Attach the sample application.           component.getDefaultHost().attach(new FirstStepsApplication());             // Start the component.           component.start();       } catch (Exception e) {           // Something is wrong.           e.printStackTrace();       }   }

【提示:需要import org.restlet.Restlet和org.restlet.data.Protocol;】
然后,编译运行。在浏览器里输入http://localhost:8182/hello,不出错误的话,浏览器将呈现"hello, world"。

5、总结
现在您已经掌握了Restlet的初步。我们希望您进一步学习“第一个资源”First resource,并且更加深入的学习“Restlet教程”Restlet tutorial。 1 楼 niweiwei 2011-06-10   你好,按照你的配置,在启动tomcat后,在浏览器里输入http://<your server name>:<its port number>/firstStepsServlet/hello地址后,不能再页面上展现hello,word,而是弹出一个下载文件的对话框,是怎么回事
谢谢

热点排行