CPS - EXPORT EXCEL & REST SERVICE

本文简要介绍了如何使用Eclipse和Tomcat快速搭建RESTful Web Services,并通过一个简单的HelloWorld示例展示了基本步骤。首先创建Web项目,然后集成RESTful Web Services所需的库文件,最后编写并部署一个简单的服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cmd 模拟 打开url:C:\Windows\System32\rundll32.exe url.dll, FileProtocolHandler http://tw.yahoo.com


<%@ page contentType="application/msexcel"%> <% // excel response.setHeader("Content-disposition", "attachment; filename=MyExcel.xls"); // ie excel //response.setHeader("Content-disposition","inline; filename=MyExcel.xls"); //Word contentType="application/msexcel" contentType="application/msword" %> <html> <head> <title>test Excel Word</title> </head> <body> <table width="500" border="1" align="center"> <thead> <tr> <th class="header">thead1</th> <th class="header">thead1</th> <th class="header">thead1</th> <th class="header">thead1</th> </tr> </thead> <tbody> <tr> <td width="7%">123</td> <td width="7%">213</td> <td width="18%">321</td> <td width="68%">332</td> </tr> <tr> <td>20061006</td> <td align="right">xxx</td> <td>xxx</td> <td>xxxxx</td> </tr> <tr> <td>20061007</td> <td>xx</td> <td>xxx</td> <td>xxxxx</td> </tr> <tr> <td>20061008</td> <td>xx</td> <td>xxx</td> <td>xxxxx</td> </tr> </tbody> </table> </body> </html>
estful web services,相信对于大多数读者来说已经不是什么新鲜的名词,网上能搜到的资料也是汗牛充栋,数不胜数,故在此本人就不再赘述,仅提供若干参考网站,同时附件中也提供一些收集到的restful web services的学习资料,有兴趣的朋友可以下载来看一下。在这里我只是想简单说一下如何利用eclipse和tomcat如何快速实现restful web services的HelloWorld。接着下来我想通过不断的学习由浅入深形成一系列的文章。

第一步:新建web项目

在eclipse中新建一个Web Project即可,地球上的java开发者都知道怎么做的

第二步:集成restful web services

把附件中的lib.zip解压后的所有jar复制到项目的lib目录下,然后在web.xml里增加如下代码:

<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

第三步:新建HelloWorld类

package net.jackshow.test;


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/helloWorld")
public class HelloWorld {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String helloWorld(){
String ret = "Hello World!";
return ret;
}
}

完成后把项目发布到tomcat,然后在浏览器中输入http://hostname:port/projectname/services/helloWorld(注:这里的hostname是指你的主机名,如localhost;port是tomcat的端口,如8080;projectname是指你第一步新建的项目名),浏览器上即打印出“Hello World!”

附:

restful web services的介绍:http://xingshaomin.iteye.com/blog/127224

java的restful web services的实现项目jersey官网:https://jersey.dev.java.net/

sun官网关于restful web services的介绍:http://java.sun.com/developer/technicalArticles/WebServices/restful/


from:http://coolzhi.iteye.com/blog/588543


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值