How to determine if a html file is a url?

Given the url, how can you determine if the specified file and html file are there?

Obviously, this is an html file if it ends with .html or /, but there are also .jsp files, so I'm wondering what other extensions might be there for html.

Alternatively, if this information can be easily obtained from a URL object in Java, that would be enough for my purposes.

+3
source share
7 answers

Just from a URL that you cannot, think of the following URLs:

HTML. - Content-TYpe. HEAD GET POST - .

  URL url = ...
  HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
  urlc.setAllowUserInteraction( false );
  urlc.setDoInput( true );
  urlc.setDoOutput( false );
  urlc.setUseCaches( true );
  urlc.setRequestMethod("HEAD");
  urlc.connect();
  String mime = urlc.getContentType();
  if(mime.equals("text/html") {
    // do your stuff
  }
+10

. , , text/html.

+20

. html URL-, .jpeg, .gif .mp3. - URL- Content-Type, , text/html ( 100% - -).

+7

, URL- - . , , , , , , - , URL. , , , , 100% - , . , , , .

, , , .

. , , , , ( ). MIME-Type "Content-Type". text/html, html- ( , xhtml, HTML).

+4
+2

HTML - , , html , *.html, HTML-, *.jsp, *.php, *.asp .. html. , , -, .

+1

. URL .html, html. spring, .html, html URL-, . .

0

Source: https://habr.com/ru/post/1711612/


All Articles