常见问题
可以从Java servlet的doGet
方法发送get reguest 吗?我需要检查一些针对我的Web API
.NET服务的“凭单”,因此我可以从该doGet
方法中的自定义servlet调用此服务吗?
public class IdentityProviderServlet extends HttpServlet {
...
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
...
// make request to Web API and save received user name to response
...
}
细节
我们有使用TIBCO Spotfire
7.0作为分析报告引擎的Web应用程序(.NET,MVC5)。为了使我们的用户能够在Web应用程序中查看报告,我们使用Spotfire
WebPlayer(IIS Web应用程序)和JavaScript API。我们在网络应用中对我们的用户进行身份验证,然后允许他们利用JS
API向WebPlayer请求。为了使用已通过验证的用户,我们在Web播放器基于键客票实现自定义验证描述在这里。因此,我们创建了.NET程序集,该程序由Spotfire
WebPlayer加载并调用覆盖的函数。在此函数中,我们调用Web
API服务来验证用户并获取有效的Spotfire用户名,然后IIdentity
使用接收到的用户名进行创建。当新版本的TIBCO Spotfire
7.5发布时,我们发现它们已删除支持自定义身份验证,因为它们更改了体系结构,现在它们支持“
外部身份验证
”。这种方法可以作为Java Servlet实施,用于验证用户身份,然后进行点射击:
从javax.servlet.http.HttpServletRequest的getUserPrincipal()方法检索用户名
所有这些迫使我们用Java重新编写逻辑。但是,我们不想更改身份验证的整体工作流程,而希望坚持使用已经可用的票证架构。我是Java
servlet的新手,因此我的目标是基于servlet实现相同的身份验证。他们有一个示例,其中servlet类具有方法doGet
和doPost
(带有示例的zip链接)。我在这里的假设是,我可以实现自己的doGet
请求并将请求发送到Web
API以验证票证并获取用户名。
是否有意义 ?
您可以使用库Apache HTTP Components
doGet()
(我没有编译)的简短示例:
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
{
String url="http://your.server.com/path/to/app?par1=yxc&par2=abc");
HttpGet get=new HttpGet(url);
httpClient = HttpClients.createDefault();
// optional configuration
RequestConfig config=RequestConfig.custom().setSocketTimeout(socketTimeoutSec * 1000).build();
// more configuration
get.setConfig(config);
CloseableHttpResponse internResponse = httpClient.execute(get);
int internResponseStatus = internResponse.getStatusLine().getStatusCode();
InputStream respIn = internResponseEntity.getContent();
String contentType = internResponseEntity.getContentType().getValue();
// consume the response
}
我正在使用JavaServlet中的javamail api发送邮件。只向gmail Id发送邮件是非常困难的,而我希望它能够发送到任何电子邮件Id。我需要不同的属性值吗?我跟着http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ 开发代码。属性值为: props.set财产(mail.smtp.
javax.net.ssl.sslhandShakeException:收到致命警报:在com.ibm.jsse2.O.A(O.java:8)在com.ibm.jsse2.sslsocketimpl.B(SSLSocketimpl.java:40)在com.ibm.jsse2.sslsocketimpl.A(SSLSocketimpl.java:554)在com.ibm.jsse2.sslsock
如何通过代码将我的响应和请求对象从jsp文件发送到servlet?我不想提交表单之类的。 我试过了: 但它说: 澄清一下:我有一个客户端向JSP文件发送一个post请求。这个JSP文件解析一个文件并将所需的信息放入会话中。我想从这个jsp文件中调用一个servlet来向数据库中添加一些东西。我认为这个错误代码是由这行
response.content=statuscode:401,reasonprace:'unauthorized',version:1.1,content:system.net.http.streamcontent,header:{ rlogid:t6ldssk%28ciudbq%60anng%7fu2h%3f%3cwk%7difvqn*14%3f0513%29pqtfwpu%29pdhcaj%
我想存储从中接收请求的URL/ip。 例如,I am(服务器)从ip地址176.15.14.3接收请求。 我想获取ip地址176.15.14.3 我可以用Spring来做吗。
XMLHttpRequest 对象用于和服务器交换数据。 向服务器发送请求 如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 open() 和 send() 方法:xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); 方法 描述 open(method,url,async) 规定请求的类型、URL 以及是否异步处理