gpt4 book ai didi

java - 在我的程序中建立 URL 连接后未获取请求/响应中的值?

转载 作者:行者123 更新时间:2023-11-30 04:55:58 25 4
gpt4 key购买 nike

我有以下应用程序(例如App1)位于tomcat上的端口8888上,它正在打开与位于tomcat上的端口8080上的另一个Web应用程序(例如App2)的url连接

 String urlStr = "http://localhost:8080/myWebApp/xwiki/auth/my-auth!checkAuth.action" 
URLConnection conn = url.openConnection();
/ Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();//Line1

使用上面的代码,它会在 8080 端口上访问我的 servlet AuthenticationServlet,该 servlet 在请求和返回中设置属性 XWikiAuthentication

request.setAttribute("XWikiAuthentication", "Successful"); 
return;

但我没有在我的应用程序 App1 中获取参数 XWikiAuthentication 的值。我在 App1 中的 line1 下面尝试了两种方法

方法1:- 串线; while ((line = rd.readLine()) != null) { sb.append(行); 结果 = sb.toString(); }

方法2:-

 String Response=request.getAttribute("XWikiAuthentication");
String Response1=request().getParameter("XWikiAuthentication");
but got the value as nullthough iam expecting value as successfull

我不知道如何在 app2 的应用程序的 App1 中设置参数 XWikiAuthentication 的值?

更新:- 我正在使用 Struts2

最佳答案

不确定我是否完全理解了这个问题。 重述 - 您想要访问另一个 Web 应用程序,该应用程序本质上是一个身份验证 servlet,并且想要读回用户是否已通过身份验证?

假设以上 -

您应该将用户详细信息(在 request 对象中)发送到身份验证 servlet,并在其中设置 response 中的最终状态,这就是您应该做的正在读书。您可以将其设置为响应中的 http header 值,也可以直接将其写入身份验证 servlet 的 outputstream

记住 - 您发送请求并获取响应。请参阅Using Url Connection

关于java - 在我的程序中建立 URL 连接后未获取请求/响应中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8530137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com