zoukankan      html  css  js  c++  java
  • rest入门实践之一:

    首先准备开发工具:Myeclipse   jdk1.6

    1.建立webservice,发布选择rest

    2.选择src建立一个类,将这个类作为发布的类,

        

    3.后台代码:

    package com.rest.helloworld;

    import javax.ws.rs.DefaultValue;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.QueryParam;

    @Path("helloworld")
    public class HelloWorld {

    @GET
    @Path("sayHello")
    public String sayHello(
    @DefaultValue("hello world") @QueryParam("queryname") String name) {
    return name;
    }
    }

    4.tomcat发布服务,访问:http://localhost/RestPractice/services/helloworld/sayHello

    即可见到:

    也可以通过javascript 之AJAX来访问:

    如:

    <script type="text/javascript">
    var xmlhttp;
    function createXmlHttpRequest(){
    if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
    }else{

    xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
    }
    }

    function getMsg(){
    createXmlHttpRequest();
    xmlhttp.open("get","http://localhost/RestPractice/services/helloworld/sayHello?queryname=sun",true);
    xmlhttp.onreadystatechange = getMsgCallBack;
    xmlhttp.send(null);
    }

    function getMsgCallBack(){
    if(xmlhttp.status == 200){
    if(xmlhttp.readyState == 4){
    alert(xmlhttp.responseText);
    }
    }
    }

    </script>

    即可得到:

  • 相关阅读:
    三维形体的表面积
    访问所有点的最小时间
    链式队列
    顺序队列
    链栈
    顺序栈
    双向链表
    pyrhon 开始 基础类型
    GDI+_VB6_ARGB
    WindowsPhone自定义控件详解(一)
  • 原文地址:https://www.cnblogs.com/pony1223/p/rest.html
Copyright © 2011-2022 走看看