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

Servlets/JSP Java Discussion :

problème appel d'une classe à partir jsp


Sujet :

Servlets/JSP Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    133
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 133
    Par défaut problème appel d'une classe à partir jsp
    bonjour tout le monde,

    voilà, j'ai une classe SimpleTTS qui tourne correctement lorsque je la compile.
    ma question, c'est comment faire l'appel de cette classe dans une jsp.
    ce que j'ai fait :
    1) j'ai enlevé le main de la classe et j'ai mis le corps de cette méthode dans la jsp
    2) je l'ai mise dans le WEB-INF de mon application
    3) j'instancie ma classe dans ma JSP grâce à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SimpleTTS voz = new SimpleTTS("kevin16");
    à signaler que bien évidemment la classe contient un constructeur

    ma question est :
    1) doit on faire un import ? j'ai essayé, ça marche pas, peut être que j'y prend mal.
    2) quelqu'un peut-il me dire comment levé cette exception:
    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
    org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP
     
    Erreur de servlet générée:
    Only a type can be imported. com.sun.speech.freetts.audio.AudioPlayer resolves to a package
     
    Erreur de servlet générée:
    Only a type can be imported. com.sun.speech.freetts.audio.NullAudioPlayer resolves to a package
     
    Erreur de servlet générée:
    Only a type can be imported. com.sun.speech.freetts.audio.SingleFileAudioPlayer resolves to a package
     
    Erreur de servlet générée:
    Only a type can be imported. com.sun.speech.freetts.Voice resolves to a package
     
    Erreur de servlet générée:
    Only a type can be imported. com.sun.speech.freetts.VoiceManager resolves to a package
     
    Une erreur s'est produite à la ligne: 14 dans le fichier jsp: /LOURD/TextToSpeech.jsp
    Erreur de servlet générée:
    SimpleTTS cannot be resolved to a type
     
    Une erreur s'est produite à la ligne: 14 dans le fichier jsp: /LOURD/TextToSpeech.jsp
    Erreur de servlet générée:
    SimpleTTS cannot be resolved to a type
     
     
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    merci d'avance pour vos réponses!

  2. #2
    Membre émérite
    Avatar de kmdkaci
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 560
    Par défaut problème appel d'une classe à partir jsp
    Bonjour,
    J'avoue que j'ai pas bien compris ta demande, notamment que tu dis : j'ai enlevé le main de la classe et j'ai mis le corps de cette méthode dans la jsp.
    Mais pour appeler une méthode d'une classe à partir d'une JSP, on fait comme suit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SimpleTTS voz = new SimpleTTS("kevin16");
    voz.maMethode(parametre1, parametre2);
    Le mieux c'est que tu poste les bouts de code concernés par ton erreur..

  3. #3
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    133
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 133
    Par défaut
    merci pour ta réponse.

    pour ce qui concerne le main, en fait ce que j'ai fait, j'ai créer une classe java et pour tester la classe, j'ai créer une méthode main. (un fichier java classique quoi!)

    ensuite, j'ai voulu intégrer cette classe pour faire son appel à partir d'une JSP (j'espère que j'ai été claire)

    C'est une classe qui permet de faire du text to speech:
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    import java.io.*;
    import com.sun.speech.freetts.audio.AudioPlayer;
    //import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
    //import com.sun.speech.freetts.audio.MultiFileAudioPlayer;
    import com.sun.speech.freetts.audio.NullAudioPlayer;
    //import com.sun.speech.freetts.audio.RawFileAudioPlayer;
    import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
    //import java.io.*;
    //import java.net.URL;
    //import javax.sound.sampled.AudioFileFormat;
    import javax.sound.sampled.AudioSystem;
    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;
     
    public class SimpleTTS
    {
    Voice voice=null;
    //constructeur
    public SimpleTTS()
    {
    }
    public SimpleTTS(String voiceName) throws Exception
    {
    VoiceManager voiceManager = VoiceManager.getInstance();
    this.voice = voiceManager.getVoice(voiceName);
    if (this.voice == null)
    {
    System.out.println("La lista de voces disponibles es:");
    listAllVoices();
    throw new Exception("No se encuentra la voz llamada: "+voiceName+". Por favor selecciona una voz diferente.");
    }
    this.voice.allocate();
    }
    //-
    public void speak(String text) throws Exception
    {
    this.voice.speak(text);
    }
    //-
    public void toFile(String filename,String text) throws Exception
    {
    javax.sound.sampled.AudioFileFormat.Type type = getAudioType(filename);
    AudioPlayer audioPlayer = null;
    if(audioPlayer == null)
    audioPlayer = new NullAudioPlayer();
    audioPlayer = new SingleFileAudioPlayer(getBasename(filename), type);
    System.out.println("audioPlayer "+audioPlayer);
    this.voice.setAudioPlayer(audioPlayer);
    this.voice.speak(text);
    audioPlayer.close();
    }
    //-
    public void close() throws Exception
    {
    this.voice.deallocate();
    }
    //-
    public static  void listAllVoices()
    {
    System.out.println();
    System.out.println("All voices available:");
    VoiceManager voiceManager = VoiceManager.getInstance();
    System.out.println("voiceManager:"+voiceManager);
    Voice[] voices = voiceManager.getVoices();
    for (int i = 0; i < voices.length; i++) {
    System.out.println(" " + voices[i].getName()
    + " (" + voices[i].getDomain() + " domain)");
    }
    }
    //-
    public javax.sound.sampled.AudioFileFormat.Type getAudioType(String file)
    {
    javax.sound.sampled.AudioFileFormat.Type types[] = AudioSystem.getAudioFileTypes();
    String extension = getExtension(file);
    for(int i = 0; i < types.length; i++)
    if(types[i].getExtension().equals(extension))
    return types[i];
    return null;
    }
    //-
    public String getExtension(String path)
    {
    int index = path.lastIndexOf(".");
    if(index == -1)
    return null;
    else
    return path.substring(index + 1);
    }
    //-
    public String getBasename(String path)
    {
    int index = path.lastIndexOf(".");
    if(index == -1)
    return path;
    else
    return path.substring(0, index);
    }
    //-
    }
    avec le main :
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
     
    /**
    *
    * FreeTTS
    * requiere en el CLASSPATH: cmu_time_awb.jar, cmu_us_kal.jar, cmudict04.jar, cmulex.jar, cmutimelex.jar,
    * en_us.jar, freets.jar, jsapi.jar
    *
    * @author jose
    * @version 0.0.0.1
    * @since JDK 1.5 / Eclipse Callisto
    */
    import com.sun.speech.freetts.audio.AudioPlayer;
    //import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
    //import com.sun.speech.freetts.audio.MultiFileAudioPlayer;
    import com.sun.speech.freetts.audio.NullAudioPlayer;
    //import com.sun.speech.freetts.audio.RawFileAudioPlayer;
    import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
    //import java.io.*;
    //import java.net.URL;
    //import javax.sound.sampled.AudioFileFormat;
    import javax.sound.sampled.AudioSystem;
    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;
    //import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
    public class SimpleTTS
    {
    Voice voice=null;
    public SimpleTTS(String voiceName) throws Exception
    {
    VoiceManager voiceManager = VoiceManager.getInstance();
    this.voice = voiceManager.getVoice(voiceName);
    if (this.voice == null)
    {
    System.out.println("La lista de voces disponibles es:");
    listAllVoices();
    throw new Exception("No se encuentra la voz llamada: "+voiceName+". Por favor selecciona una voz diferente.");
    }
    this.voice.allocate();
    }
    //-
    public void speak(String text) throws Exception
    {
    this.voice.speak(text);
    }
    //-
    public void toFile(String filename,String text) throws Exception
    {
    javax.sound.sampled.AudioFileFormat.Type type = getAudioType(filename);
    AudioPlayer audioPlayer = null;
    if(audioPlayer == null)
    audioPlayer = new NullAudioPlayer();
    audioPlayer = new SingleFileAudioPlayer(getBasename(filename), type);
    System.out.println("audioPlayer "+audioPlayer);
    this.voice.setAudioPlayer(audioPlayer);
    this.voice.speak(text);
    audioPlayer.close();
    }
    //-
    public void close() throws Exception
    {
    this.voice.deallocate();
    }
    //-
    public static void listAllVoices()
    {
    System.out.println();
    System.out.println("All voices available:");
    VoiceManager voiceManager = VoiceManager.getInstance();
    System.out.println("voiceManager:"+voiceManager);
    Voice[] voices = voiceManager.getVoices();
    for (int i = 0; i < voices.length; i++) {
    System.out.println(" " + voices[i].getName()
    + " (" + voices[i].getDomain() + " domain)");
    }
    }
    //-
    public static javax.sound.sampled.AudioFileFormat.Type getAudioType(String file)
    {
    javax.sound.sampled.AudioFileFormat.Type types[] = AudioSystem.getAudioFileTypes();
    String extension = getExtension(file);
    for(int i = 0; i < types.length; i++)
    if(types[i].getExtension().equals(extension))
    return types[i];
    return null;
    }
    //-
    public static String getExtension(String path)
    {
    int index = path.lastIndexOf(".");
    if(index == -1)
    return null;
    else
    return path.substring(index + 1);
    }
    //-
    public static String getBasename(String path)
    {
    int index = path.lastIndexOf(".");
    if(index == -1)
    return path;
    else
    return path.substring(0, index);
    }
    //-
    static public void main(String[] args) throws Exception
    {
    try
    {
    // Instanciamos para usar la voz "kevin16?
    SimpleTTS voz = new SimpleTTS("kevin16");
    // Reproduce por el altavoz
    //while (true)
    //{
    //voz.speak("auan babuluba balan bambu");
    voz.speak("Hello World!");
    //}
    voz.speak("test text to speech ");
    // Graba un fichero de audio con el contenido en el directorio
    voz.toFile("ttsdemo.wav", "Ubuntu Life is the best site of Linux");
    // Podriamos reproducir este fichero desde consola: $ mplayer ttsdemo.wav
    // Cerramos
    voz.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    //-
    }
    //end of class SimpleTTS

  4. #4
    Membre émérite
    Avatar de kmdkaci
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 560
    Par défaut problème appel d'une classe à partir jsp
    L'erreur est dans la JSP... C'est plutôt ce fichier qu'il faut poster. Sinon, comment as-tu fais les imports dans ta JSP ?

  5. #5
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    133
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 133
    Par défaut
    comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <%@ page import=" com.sun.speech.freetts.audio.AudioPlayer,
     com.sun.speech.freetts.audio.NullAudioPlayer,
     com.sun.speech.freetts.audio.SingleFileAudioPlayer,
     javax.sound.sampled.AudioSystem,
     com.sun.speech.freetts.Voice,
     com.sun.speech.freetts.VoiceManager" %>

  6. #6
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    133
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 133
    Par défaut
    pas d'indice?

Discussions similaires

  1. appel d'une classe à partir d'une servlet ou jsp
    Par mina24 dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 11/07/2010, 23h38
  2. Appel d'une classe dans une jsp
    Par _ash_ dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 05/07/2009, 13h56
  3. appel des elements d'une classe à partir d'une autre
    Par oceane751 dans le forum Langage
    Réponses: 4
    Dernier message: 02/01/2008, 21h52
  4. Réponses: 12
    Dernier message: 07/11/2007, 00h53
  5. appel d'une classe java dans un jsp
    Par kanzarih dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 01/03/2007, 13h06

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