Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从RESTWebService发送响应_Java_Javascript_Web Services_Rest - Fatal编程技术网

Java 如何从RESTWebService发送响应

Java 如何从RESTWebService发送响应,java,javascript,web-services,rest,Java,Javascript,Web Services,Rest,我不熟悉RESTWebService。我正在尝试的是,我有一个html页面,其中有一个文本框。文本框的内容将使用url发送。这是密码- <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> function restCall(){ var us

我不熟悉RESTWebService。我正在尝试的是,我有一个html页面,其中有一个文本框。文本框的内容将使用url发送。这是密码-

<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
<script>
    function restCall(){            
        var user=$('#name').val();
        var psw=$('#pswd').val();           
        var url="http://localhost:8080/JAXRS-HelloWorld/rest/helloWorldREST/"+user+"?value="+psw+";";
        alert(url);
        $(location).attr('href',url);
    }
</script>
<div style="padding-left: 300px; padding-top: 200px;">
    <input type="text" value="" id="name" /><br><br> 
    <input type="password" value="" id="pswd" /><br><br> 
    <input type="button" value="Show" onclick="restCall()"/>
</div>
</body>
此代码将输出为=>Hello from:Subho:Subho


现在我不想展示这个。这个消息可以在控制台中显示,但我想从这里调用另一个Web服务或任何链接。我的意思是,让我在html页面文本框中写下Facebook,这个页面将Facebook写到控制台,然后启动www.Facebook.com链接并转到那里。我该怎么做呢。请帮助…

我知道现在已经晚了,但是发布这个答案是希望这个答案能对其他人有所帮助

我认为您希望重定向到web服务方法中指定的URL。如果是这种情况,那么您可以使用以下响应方法

 - Response.temporaryRedirect(URI)
 - Response.seeOther(URI)
下面是示例代码

java.net.URI location = new java.net.URI("www.sometarget.com");
return Response.temporaryRedirect(location).build();
有几种类型的重定向

  • 301永久移动
    303参见其他
    307临时重定向
获取更多信息


希望这会有所帮助。

window.location.href=“www.facebook.com”为什么您需要点击服务器才能满足此要求?我不明白。似乎这可以通过一些简单的Javascript来完成,比如上面的注释或jQuery,您似乎已经知道了。
java.net.URI location = new java.net.URI("www.sometarget.com");
return Response.temporaryRedirect(location).build();