在Restful Web服务中传递参数

时间:2012-04-24 16:08:35

标签: web-services rest get

亲爱的Stackoverflow用户, 我现在已经玩了很长一段时间了。 我对如何使用GET方法传递参数有一点疑问。 由于get只能用于检索任何资源,如何传递参数。 我为此编写了一个小代码,但代码似乎有问题。

@GET
    @Produces("text/plain")
    @Path("/instrumentname/")
    public String getname(String name1) {
try {


String [] env=null;
            String[]callAndArgs= {"python","connection.py",ins_name};//passing the parameters

            Process p = Runtime.getRuntime().exec(callAndArgs,env,
                    new java.io.File("C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\Testinstrument_Rest\\build\\web"));//excuting the python file



            BufferedReader stdInput = new BufferedReader(new 

                 InputStreamReader(p.getInputStream()));//getting the input



            BufferedReader stdError = new BufferedReader(new 

                 InputStreamReader(p.getErrorStream()));//getting the error




           interface_name = stdInput.readLine();//reading the output




                System.out.println(interface_name);


    }


        catch (IOException e) {//catching the exception

            System.out.println("exception occured");

            e.printStackTrace();

            System.exit(-1);

        }
        return this.interface_name;
    } 

非常感谢任何帮助。 非常感谢提前。 干杯!

2 个答案:

答案 0 :(得分:1)

您只需要按以下格式在URL末尾连接参数: www.xyz.com/?param1=val1&param2=val2&param3=val3

其中param1,param2是参数名称,val1,val2是相应参数的值...您只需在浏览器的URL栏中键入它们,而不是编写HTML页面或脚本进行测试......

此外,您说GET通常用于从Web服务器获取资源,但有时您必须传递其资源必须被提取的信息...

答案 1 :(得分:0)

您可以使用@Queryparam注释来读取url参数。如果这是您正在寻找的内容,请参考RESTful webservices: query parameters

相关问题