A href on java windows

Creating the Web Page That Launches the Application

The following information predates the introduction of the Deployment Toolkit script in the Java SE 6 update 10 release.
See Deployment in the Browser for information about using the Deployment Toolkit script.

In order for an application to be launched from a web page via JNLP, the page must include a link to the JNLP file. E.g., to be able to launch application app.jnlp on a web site http://www.MySite.com , the page needs to include the following link:

It may be the case, however, that Java Web Start is not installed on the user’s computer. Thus the page needs to include logic (scripts) to take account of this. In fact, the page should include logic for the following:

Detect if Java Web Start is installed

  • If so, launch the application.
  • If not, detect if user is running IE on Window.
    • If so, provide link to a page that can auto-install the JRE for Windows
    • If not, provide a link to the general download page for the JDK/JRE.

    The scripts, and the HTML for the auto-install page, are discussed below.

    Detecting if Java Web Start is installed on Netscape

    Here is the first script that should be run on a web page for launching an application via JNLP:

     var javawsInstalled = 0; var javaws142Installed=0; var javaws150Installed=0; var javaws160Installed = 0; isIE = "false"; if (navigator.mimeTypes && navigator.mimeTypes.length) < x = navigator.mimeTypes['application/x-java-jnlp-file']; if (x) < javawsInstalled = 1; javaws142Installed=1; javaws150Installed=1; javaws160Installed = 1; >> else

    This script looks at the navigator.mimeTypes object and the navigator.mimeTypes.length var to decide if the browser is Netscape or IE. If length is 0, it is assumed the browser is IE, as with IE the navigator.mimeTypes array is defined but always empty. If length is non-zero, then the browser is assumed to be Netscape and the JNLP MIME type is checked to see if it exists on Netscape. If so, javawsInstalled , javaws142Installed , javaws150Installed and javaws160Installed are all set to 1. With Netscape it is not possible to determine which particular version of Java Web Start is installed, so all four variables are set to 1.

    Detecting if JavaWeb Start is installed on IE, and if so, the version

    The above JavaScript should be followed by a VBScript that sets variables related to Internet Explorer browers:

      

    This VBScript is executed if the variable isIE from the preceeding JavaScript is "true"; i.e., if the end-user’s browser is Internet Explorer. This script instantiates the isInstalled COM object in JavaWebStart.dll, and this object determines four things:

    • whether the client machine has any version of Java Web Start installed;
    • whether the client machine has version 1.2 of Java Web Start installed;
    • whether the client machine has versions 1.4.2 of Java Web Start installed;
    • whether the client machine has versions 1.5.0 of Java Web Start installed.
    • whether the client machine has versions 1.6.0 of Java Web Start installed.

    After the above two scripts have been executed, the variables javawsInstalled, javaws142Installed , javawsInstalled150 and javawsInstalled160 will be set to either 1 or 0, as follows:

    Источник

    Creating a URL

    The easiest way to create a URL object is from a String that represents the human-readable form of the URL address. This is typically the form that another person will use for a URL. In your Java program, you can use a String containing this text to create a URL object:

    URL myURL = new URL("http://example.com/");

    The URL object created above represents an absolute URL. An absolute URL contains all of the information necessary to reach the resource in question. You can also create URL objects from a relative URL address.

    Creating a URL Relative to Another

    A relative URL contains only enough information to reach the resource relative to (or in the context of) another URL.

    Relative URL specifications are often used within HTML files. For example, suppose you write an HTML file called JoesHomePage.html . Within this page, are links to other pages, PicturesOfMe.html and MyKids.html , that are on the same machine and in the same directory as JoesHomePage.html . The links to PicturesOfMe.html and MyKids.html from JoesHomePage.html could be specified just as file names, like this:

    These URL addresses are relative URLs. That is, the URLs are specified relative to the file in which they are contained — JoesHomePage.html .

    In your Java programs, you can create a URL object from a relative URL specification. For example, suppose you know two URLs at the site example.com :

    http://example.com/pages/page1.html http://example.com/pages/page2.html

    You can create URL objects for these pages relative to their common base URL: http://example.com/pages/ like this:

    URL myURL = new URL("http://example.com/pages/"); URL page1URL = new URL(myURL, "page1.html"); URL page2URL = new URL(myURL, "page2.html");

    This code snippet uses the URL constructor that lets you create a URL object from another URL object (the base) and a relative URL specification. The general form of this constructor is:

    URL(URL baseURL, String relativeURL)

    The first argument is a URL object that specifies the base of the new URL . The second argument is a String that specifies the rest of the resource name relative to the base. If baseURL is null, then this constructor treats relativeURL like an absolute URL specification. Conversely, if relativeURL is an absolute URL specification, then the constructor ignores baseURL .

    This constructor is also useful for creating URL objects for named anchors (also called references) within a file. For example, suppose the page1.html file has a named anchor called BOTTOM at the bottom of the file. You can use the relative URL constructor to create a URL object for it like this:

    URL page1BottomURL = new URL(page1URL,"#BOTTOM");

    Other URL Constructors

    The URL class provides two additional constructors for creating a URL object. These constructors are useful when you are working with URLs, such as HTTP URLs, that have host name, filename, port number, and reference components in the resource name portion of the URL. These two constructors are useful when you do not have a String containing the complete URL specification, but you do know various components of the URL.

    For example, suppose you design a network browsing panel similar to a file browsing panel that allows users to choose the protocol, host name, port number, and filename. You can construct a URL from the panel’s components. The first constructor creates a URL object from a protocol, host name, and filename. The following code snippet creates a URL to the page1.html file at the example.com site:

    new URL("http", "example.com", "/pages/page1.html");
    new URL("http://example.com/pages/page1.html");

    The first argument is the protocol, the second is the host name, and the last is the pathname of the file. Note that the filename contains a forward slash at the beginning. This indicates that the filename is specified from the root of the host.

    The final URL constructor adds the port number to the list of arguments used in the previous constructor:

    URL gamelan = new URL("http", "example.com", 80, "pages/page1.html");

    This creates a URL object for the following URL:

    http://example.com:80/pages/page1.html

    If you construct a URL object using one of these constructors, you can get a String containing the complete URL address by using the URL object’s toString method or the equivalent toExternalForm method.

    URL addresses with Special characters

    Some URL addresses contain special characters, for example the space character. Like this:

    http://example.com/hello world/

    To make these characters legal they need to be encoded before passing them to the URL constructor.

    URL url = new URL("http://example.com/hello%20world");

    Encoding the special character(s) in this example is easy as there is only one character that needs encoding, but for URL addresses that have several of these characters or if you are unsure when writing your code what URL addresses you will need to access, you can use the multi-argument constructors of the java.net.URI class to automatically take care of the encoding for you.

    URI uri = new URI("http", "example.com", "/hello world/", "");

    And then convert the URI to a URL.

    MalformedURLException

    Each of the four URL constructors throws a MalformedURLException if the arguments to the constructor refer to a null or unknown protocol. Typically, you want to catch and handle this exception by embedding your URL constructor statements in a try / catch pair, like this:

    try < URL myURL = new URL(. ); >catch (MalformedURLException e) < // exception handler code here // . >

    See Exceptions for information about handling exceptions.

    URL s are «write-once» objects. Once you’ve created a URL object, you cannot change any of its attributes (protocol, host name, filename, or port number).

    Источник

    Популярные HTML-теги

    Ну, мы все же не забываем, что готовим из тебя Java-программиста, поэтому тебе нужно изучить всего 5 тегов.

    Во-первых, это самый важный тег, который превращает текст в гипертекст – ссылка. Для создания ссылок в HTML используется тег

    Стандартная ссылка имеет вид:

      href="адрес-ссылки">текст ссылки  

    Где синим отображен текст, который видит пользователь, а зеленым – адрес (ссылка) на которую он перейдет, если кликнет по тексту ссылки.

    А типичный HTML-документ, содержащий ссылки выглядит так:

      Обычный текст  href="http://javarush.ru/about"> Ссылка на что-то интересное еще какой-то текст 

    Хотя нет, обычно это выглядит так:

      Обычный текст  href="http://javarush.ru/about">Ссылка на что-то интересное еще какой-то текст 

    4.2 Тег img и атрибут src

    Для вставки картинки в HTML-страницу используется тег (от слова image). Это одиночный тег, закрывающего тега у него нет. Общий вид тега:

    Все очень просто. Для того, чтобы отобразить картинку в твоём HTML-документе, просто нужно знать ссылку на эту картинку и использовать тег img . Попробуй, тебе понравится.

    4.3 Элемент table

    Также HTML-страница может содержать таблицу с данными. Но тут уже одним тегом не обойдешься, если подумать. Ведь у таблицы есть заголовок, строки, колонки и ячейки. Для них всех придумали свои теги:

    Вот как будет выглядеть таблица 3 на 3 в html (с дополнительной строкой-заголовком)

        Фамилия Имя Отчество   Иванов Иван Иванович   Петров Петр Петрович   Сидоров Коля Сидоренко   

    Хотя сейчас таблицы стали использоваться редко. Все дело в том, что при просмотре страницы с телефона, таблицу бывает полезно отобразить по-другому (она просто не помещается на экране). Но знать как устроены таблицы тебе все равно нужно.

    4.4 Атрибуты id и name

    И еще два важных момента – это атрибуты id и name . Это именно атрибуты, а не теги, но используются они очень часто.

    Атрибут id у тега позволяет задать ему имя, уникальное в рамках всего документа . Это бывает полезно, если в HTML-документе есть какой-нибудь JavaScript, который меняет значение или параметры данного тега. Тогда с помощью уникального id можно точно обратиться к нужному тегу.

    Атрибут name выполняет похожую функцию, но его значение не обязано быть уникальным в рамках страницы. То есть теоретически может быть несколько тегов с одинаковыми именами. Это сделано для более удобной работы с группами элементов.

    Например, на странице есть несколько списков в каждом из которых можно выбрать только один элемент. Тогда при выборе нового элемента в списке нужно сбросить выбор остальных элементов списка. Но другие списки при этом не трогать. Это можно легко сделать, если все элементы одного списка будут иметь одинаковые имена.

    У любого тега могут быть одновременно атрибуты id и name . Пример:

     id="image123" name="avatar" src="https://javarush.com/quests/lectures/%D1%81%D1%81%D1%8B%D0%BB%D0%BA%D0%B0%20%D0%BD%D0%B0%20%D0%BA%D0%B0%D1%80%D1%82%D0%B8%D0%BD%D0%BA%D1%83"> 

    Источник

    Читайте также:  Before css pseudo element
Оцените статью