小编Pau*_*bin的帖子

HTTP PUT请求可以将application/x-www-form-urlencoded作为Content-Type吗?

如果我需要在HTTP PUT请求中发送表单数据,它是否有效?

如果你能指出我的规格,那就太棒了.

[更新]

我已经完成了HTTP 1.1规范.但我没有发现PUT请求是否可以有Form数据.

我正在使用Java来创建和访问RESTful webservices.POST支持application/x-www-form-urlencoded作为Content-Type.

根据规范,我了解POST用于创建新资源(由请求URI标识的资源的子资源),PUT用于创建或更新资源.

但我怀疑PUT方法是否也可以有表格数据呢?我试图根据规格找出它是否合适.我在HTTP 1.1规范中找不到任何相关内容.

谢谢,保罗

rest specifications content-type http put

15
推荐指数
2
解决办法
2万
查看次数

如何在Javascript中声明动态局部变量

我想动态创建一个局部变量.JavaScript:动态创建循环变量并不是我想要的.我不想要一个阵列.我想像局部变量一样访问它.

就像是:

    <script type="text/javascript">
        var properties = new Object();
        properties["var1"] = "value1";
        properties["var2"] = "value2";

        createVariables(properties);

        function createVariables(properties)
        {
            // This function should somehow create variables in the calling function. Is there a way to do that?
        }
        document.write("Outside the function : " + var1 + "<br>");
        document.write("Outside the function : " + var2 + "<br>");
    </script>
Run Code Online (Sandbox Code Playgroud)

我尝试了以下代码.

    <script type="text/javascript">
        var properties = new Object();
        properties["var1"] = "value1";
        properties["var2"] = "value2";

        createVariables(properties);

        function createVariables(properties)
        {
            for( var variable …
Run Code Online (Sandbox Code Playgroud)

javascript

13
推荐指数
2
解决办法
8280
查看次数

如何在 Jersey 中动态指定默认值?

我正在使用 Java Jersey 库来创建 RESTful Web 服务。

我正在使用查询参数作为方法。我想为该查询参数指定默认值。如果我指定一个常量字符串,那就没问题了。但是如何将运行时值指定为默认值?

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

@Path( "Hello" ) 
public class HelloWorld 
{ 
    private String defaultValue = "Default"; 

    @GET 
    @Produces( MediaType.APPLICATION_XML ) 
    public String greet( @QueryParam( "User" ) @DefaultValue( "defaultValue" )String userName ) 
    { 
        String returnValue = "Hello " + userName; 
        System.out.println( returnValue ); 
        return returnValue; 
    } 
} 
Run Code Online (Sandbox Code Playgroud)

我如何在这里使用变量而不是常量?有可能吗?

java rest annotations web-services jersey

6
推荐指数
1
解决办法
4766
查看次数

使用reduce和collect查找平均值

我试图了解新的Java 8 Stream API.

http://docs.oracle.com/javase/tutorial/collections/streams/reduction.html

我找到了使用collect API查找数字平均值的示例.但我觉得,使用reduce()也可以做同样的事情.

public class Test {

    public static void main(String[] args) {
        // Using collect
        System.out.println(Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .collect(Averager::new, Averager::accept, Averager::combine)
            .average());

        // Using reduce
        System.out.println(Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .reduce(new Averager(), (t, u) -> {
                t.accept(u);
                return t;
            }, (t, u) -> {
                t.combine(u);
                return t;
            }).average());
    }

    private static class Averager {
        private int total = 0;
        private int count = …
Run Code Online (Sandbox Code Playgroud)

java lambda functional-programming java-8 java-stream

5
推荐指数
1
解决办法
4607
查看次数

轴2是否支持REST?

我想在我们的平台上提供REST支持.我们已经在我们的框架中集成了Axis 2.Axis 2正在支持REST.所以我在考虑使用Axis 2本身来提供REST支持.

http://axis.apache.org/axis2/java/core/docs/rest-ws.html

我还发现了另一篇关于如何使用Axis 2创建RESTful Web服务的博客文章.

http://wso2.org/library/3726

但在上面的例子中,似乎我必须修改生成的WSDL以支持REST类型的调用.我必须修改轴2生成的默认WSDL2.0,修改它并在aar文件中再次打包并部署服务.所以这一次,它不使用生成wsdl,而是使用打包的WSDL并使用此WSDL来创建轴服务.这是一个问题,我必须以某种方式克服.

但Axis 2是否支持所有REST功能?我发现它支持指定要使用的HTTPMethod,HTTPLocation,InputSerialization,OutputSerialization.这些足以说明我们提供REST支持吗?

保罗先生,谢谢

java rest axis2 web-services

4
推荐指数
1
解决办法
5362
查看次数