在 HttpSession 中 session = request.getSession(); “请求”在哪里?对象定义?
使用 twitter4j 和 java,我尝试使用以下代码连接到 Twitter。在我的 java 类中,我有以下代码。
Twitter twitter = new Twitter();
twitter.setOAuthConsumer(consumerKey,consumerSecret);
RequestToken requestToken = twitter.getOAuthRequestToken();
String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();
HttpSession session = request.getSession();
session.setAttribute("token",token);
session.setAttribute("tokenSecret",tokenSecret);
我从教程中得到了这个代码。我遇到的问题是
HttpSession session = request.getSession();
对象“请求”定义在哪里?
我的程序是一个本地主机程序,完全用Java编写。我正在尝试学习如何使用 Twitter API
Using twitter4j and java, I am trying to use the following code to connect to Twitter. In my java class I have the following code.
Twitter twitter = new Twitter();
twitter.setOAuthConsumer(consumerKey,consumerSecret);
RequestToken requestToken = twitter.getOAuthRequestToken();
String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();
HttpSession session = request.getSession();
session.setAttribute("token",token);
session.setAttribute("tokenSecret",tokenSecret);
I got this code from a tutorial. The problem I am having is with the line
HttpSession session = request.getSession();
Where is the object "request" defined?
My program is a localhost program, entirely in Java. I am trying to learn how to use the Twitter API
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是一个你应该自己回答的问题。看起来您的教程假设它是从 Servlet 或 JSP 运行,其中有一个 HttpServletRequest 对象看起来可以填补这些角色。不过,它似乎被使用的唯一原因是 HTTP 会话是在 Web 应用程序中存储 oauth 令牌和机密的便捷位置。您可以将它们放在任何地方,只要稍后可以取回即可。
That sounds like a question that you should be answering yourself. It looks like your tutorial assumed it was running from a Servlet or JSP, where there's an HttpServletRequest object available that looks like it would fill those roles. The only reason it seems to be used, though, is because the HTTP session is a convenient place to store the oauth token and secret in a webapp. You can put them anywhere as long as you can get them back later.