简体   繁体   English

如何检查java是否存在网页?

[英]How do i check if a webpage exists with java?

So here's the deal. 所以这是交易。 I don't have it yet, but starting Friday, I'm in the process of making a forum. 我还没有,但从星期五开始,我正在建立一个论坛。 What I'd like to do is check to see if a user is registered on the forum. 我想做的是检查用户是否在论坛上注册。

I'm not sure exactly, but lets say the users are stored in URL/users/NAME.WHATEVER (jsp?) 我不确定,但是让我们说用户存储在URL / users / NAME.WHATEVER(jsp?)中

how, in java, do i make a URL connection, and check to see if URL/users/Robert.WHATEVER == null? 如何在java中建立URL连接,并检查URL / users / Robert.WHATEVER == null?

Even you could have googled your answer: One simple way is to use the Apache Http Components 即使你可以用google搜索你的答案:一种简单的方法是使用Apache Http组件

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://localhost/users/Robert.WHATEVER");
HttpResponse response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 404) {
   System.out.println("User Robert.WHATEVER not found");
}

There is a good Tutorial with many examples which explains how to use the HttpClient. 有一个很好的教程,有很多例子可以解释如何使用HttpClient。

Another highlevel framework is the ResteasyClientFramework . 另一个高级框架是ResteasyClientFramework

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM