IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

methode java qui ouvre une navigation vers une url


Sujet :

avec Java

  1. #1
    Candidat au Club
    Inscrit en
    Août 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 3
    Points : 2
    Points
    2
    Par défaut methode java qui ouvre une navigation vers une url
    bonjour,

    j'ai envie de savoir quelle est la méthode java qui ouvre une navigation vers une URL donnée.(j'ai envie de mettre cette url :/localhost/web/stat/index.php

    Merci.

  2. #2
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    Tu souhaites ouvrir un navigateur avec une URL précise ?

  3. #3
    Membre expérimenté
    Avatar de visiwi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    1 050
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 1 050
    Points : 1 340
    Points
    1 340
    Par défaut
    Salut,

    La réponse ne serait-elle pas dans la FAQ ?

  4. #4
    Candidat au Club
    Inscrit en
    Août 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    bonsoir,

    j'ai envie de remplacer l'appel au NavigationHandler.handleNavigation par une méthode Java qui ouvre une navigation vers une URL donnée.
    voici mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if (navigate) {
                    context.getApplication().getNavigationHandler()
                            .handleNavigation(context, null, OUTCOME_BROWSE);
                }

    que dois je faire

    Merci.

  5. #5
    Invité
    Invité(e)
    Par défaut
    Ca ressemble à du JSF ça...
    Tu veux juste faire un redirect vers une adresse externe à ton contexte ?
    Si oui alors un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    FacesContext.getCurrentInstance().getExternalContext().redirect("http://mon/url");

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 149
    Points : 95
    Points
    95
    Par défaut
    Y a pas vraiment de méthode toute faite mais il faut utiliser les Objet Process et Runtime. Je te mets un exemple. C'est pas très dur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    package javaapplication7;
     
    import java.io.IOException;
     
    /* Note - you must include the url type -- either "http://" or
     * "file://".
     */
    public class OpenWebBrowser {
     
        /**
         * Display a file in the system browser. To display a
         * file, you must include the absolute path name.
         *
         * @param url the file's url (the url must start with either "http://"
         * or "file://").
         */
        public static void openWebPage(String url) {
            boolean windows = isWindowsPlatform();
            String web_page_url = null;
            try {
                if (windows) {
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    web_page_url = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Process p = Runtime.getRuntime().exec(web_page_url);
                } else {
                    // Under Unix, Netscape has to be running for the "-remote"
                    // command to work.  So, we try sending the command and
                    // check for an exit value.  If the exit command is 0,
                    // it worked, otherwise we need to start the browser.
                    // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
                    web_page_url = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
                    Process p = Runtime.getRuntime().exec(web_page_url);
                    try {
                        // wait for exit code -- if it's 0, command worked,
                        // otherwise we need to start the browser up.
                        int exitCode = p.waitFor();
                        if (exitCode != 0) {
                            // Command failed, start up the browser
                            // cmd = 'netscape http://www.javaworld.com'
                            web_page_url = UNIX_PATH + " " + url;
                            p = Runtime.getRuntime().exec(web_page_url);
                        }
                    } catch (InterruptedException x) {
                        System.err.println("Error bringing up browser, cmd='" +
                                web_page_url + "'");
                        System.err.println("Caught: " + x);
                    }
                }
            } catch (IOException x) {
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + web_page_url);
                System.err.println("Caught: " + x);
            }
        }
     
        /**
         * Try to determine whether this application is running under Windows
         * or some other platform by examing the "os.name" property.
         *
         * @return true if this application is running under a Windows OS
         */
        public static boolean isWindowsPlatform() {
            String os = System.getProperty("os.name");
            if (os != null && os.startsWith(WIN_ID)) {
                return true;
            } else {
                return false;
            }
        }
     
     
        public static void main(String[] args) {
            openWebPage("http://www.yahoo.com");
        }
        // Used to identify the windows platform.
        private static final String WIN_ID = "Windows";
        // The default system browser under windows.
        private static final String WIN_PATH = "rundll32";
        // The flag to display a url.
        private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
        // The default browser under unix.
        private static final String UNIX_PATH = "netscape";
        // The flag to display a url.
        private static final String UNIX_FLAG = "-remote openURL";
    }
    J'espère que ça va t'aider.

  7. #7
    Nouveau membre du Club
    Inscrit en
    Juillet 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 21
    Points : 30
    Points
    30
    Par défaut ouvrir une page web
    une méthode facile pour ouvrir une page web :


    http://java-java-code.blogspot.com/2...avigation.html


    salutations ,
    khalid,

Discussions similaires

  1. [VB.Net] Comment copier une DataRow d'une table vers une autre ?
    Par YLF dans le forum Accès aux données
    Réponses: 7
    Dernier message: 05/09/2012, 23h23
  2. [C#] transferer une ligne d'une datagrid vers une autre datagrid
    Par nassimmm dans le forum Windows Forms
    Réponses: 4
    Dernier message: 11/08/2006, 09h38
  3. copier une ligne d'une table vers une autre
    Par Adren dans le forum Langage SQL
    Réponses: 5
    Dernier message: 08/08/2006, 11h54
  4. copier une partie d'une image vers une autre
    Par gregcat dans le forum Langage
    Réponses: 1
    Dernier message: 14/04/2006, 13h39
  5. [VB.NET] Copie d'une table d'une DB vers une autre
    Par SergeF dans le forum Windows Forms
    Réponses: 9
    Dernier message: 20/11/2004, 09h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo