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

Web Perl Discussion :

Intégration CSS et CGI


Sujet :

Web Perl

  1. #1
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut Intégration CSS et CGI
    Bonjour

    Je tente via une fonction d'intégrer un style CSS dans mon script CGI dont voici le code:
    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
    #!"C:\xampp\perl\bin\perl.exe"
     
    use strict;
    use warnings;
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
     
    $CGI::POST_MAX=1024*100;
    $CGI::DISABLE_UPLOADS=1;
     
    my $cgi=new CGI;
     
    # variables layout
    my $charset='';
    my $lang='';
    my $title='';
    my $distribution='';
    my $resource_type='';
    my $description='';
    my $keywords='';
    my $shortcut_icon='';
     
    &style_sheet;
     
    # css layout
    sub style_sheet {
      print <<EOS;
      <style type="text/css" media="screen">
      body {
        color:#666666;
      }
      </style>
    EOS
    }
     
    # skeleton layout
    print $cgi->header(-charset=>$charset),
        $cgi->start_html(
            -lang=>$lang,
            -title=>$title,
            -meta=>{
                'distribution'=>$distribution,
                'resource-type'=>$resource_type,
                'description'=>$description,
                'keywords'=>$keywords},
            -head=>[Link({-rel=>'shortcut icon',-href=>$shortcut_icon})],
            -style=>{-type=>'text/css',-media=>'screen',-code=>$style_sheet}),
        $cgi->end_html();
    J'appelle la fonction au démarrage du script, mais j'ai un trou de mémoire pour renseigner le champ suivant:
    Cela m'indique le message d'erreur suivant:
    Global symbol "$style_sheet" requires explicit package name at C:/xampp/cgi-bin/generic.cgi line 46.
    Un petite aide serait la bienvenue, en vous remerciant par avance

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Tu n'as pas déclaré la variable avec my !

  3. #3
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    Oups, je l'avais oublié, merci, mais du coup en la déclarant cela me génère un autre message d'erreur:
    Error message:
    malformed header from script. Bad header= <style type="text/css" media: generic.cgi
    Le code modifié:
    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
    #!"C:\xampp\perl\bin\perl.exe"
     
    use strict;
    use warnings;
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
     
    $CGI::POST_MAX=1024*100;
    $CGI::DISABLE_UPLOADS=1;
     
    my $cgi=new CGI;
     
    # variables layout
    my $charset='';
    my $lang='';
    my $title='';
    my $distribution='';
    my $resource_type='';
    my $description='';
    my $keywords='';
    my $shortcut_icon='';
    my $style_sheet;
     
    # call functions
    &style_sheet;
     
    # css layout
    sub style_sheet {
    print <<EOS;
    <style type="text/css" media="screen">
    body {
    color:#666666;
    }
    </style>
    EOS
    }
     
    # skeleton layout
    print $cgi->header(-charset=>$charset),
        $cgi->start_html(
            -lang=>$lang,
            -title=>$title,
            -meta=>{
                'distribution'=>$distribution,
                'resource-type'=>$resource_type,
                'description'=>$description,
                'keywords'=>$keywords},
            -head=>[Link({-rel=>'shortcut icon',-href=>$shortcut_icon})],
            -style=>{-code=>$style_sheet}),
        $cgi->end_html();
    Je ne comprends plus

  4. #4
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Tu te mélanges les pinceaux. Tu est en train de créer une balise <style> avant même la balise <html>, CGI te dit que ton HTML n'a pas de sens .

    Voici un exemple d'écriture :

    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
      print $cgi->header(
        -lang => "fr-en",
        -head => meta(
          { -http_equiv => "content-type",
            -content    => "text/html; charset=ISO-8859-1",
          },
          { -http_equiv => "PRAGMA",
            -content    => "NO-CACHE",
          },
        ),
      );
      print $cgi->start_html(
        -title => $titre,
        -style => { "src" => $feuille_css },
        -script =>
            { -language => "JAVASCRIPT", -src => $feuille_javascript },
      );

  5. #5
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    print $cgi->start_html(
    -style => { "src" => $feuille_css },
        -script =>{ -language => "JAVASCRIPT", -src => $feuille_javascript },
      );
    Si j'ai bien compris, ce code propose deux méthodes pour mettre en place la feuille de style ?

    Soit la méthode "src" soit Javascript ?

  6. #6
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    non, je t'ai mis un vieux code que j'ai retrouvé chez moi. j'y mettais le javascript et css, mais tu peux enlever le javascript si tu veux.

  7. #7
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    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
    #!"C:\xampp\perl\bin\perl.exe"
     
    use strict;
    use warnings;
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
     
    $CGI::POST_MAX=1024*100;
    $CGI::DISABLE_UPLOADS=1;
     
    my $cgi=new CGI;
     
    # variables layout
    my $charset='';
    my $lang='';
    my $title='';
    my $distribution='';
    my $resource_type='';
    my $description='';
    my $keywords='';
    my $shortcut_icon='';
    my $style_sheet;
     
    # call functions
    &style_sheet;
     
    # css layout
    sub style_sheet {
      print <<EOS;
      <style type="text/css" media="screen">
    body {
    color:#666666;
    }
    </style>
    EOS
    }
     
    # skeleton layout
    print $cgi->header(
                    -lang=>$lang,
                    -charset=>$charset,
                    -head=> meta (
                               {
                                   'distribution'=>$distribution,
                                   'resource-type'=>$resource_type,
                                   'description'=>$description,
                                   'keywords'=>$keywords,
                               },
                             ),
                  );
    print    $cgi->start_html(
            -title=>$title,
            -style=>{"src"=>$style_sheet},
            );
    Et bah j'ai toujours le même message d'erreur

  8. #8
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Décidément, t'as pas saisi .

    Voici ton code remis au propre et te fournissant un résultat concluant.
    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
    #!"C:\xampp\perl\bin\perl.exe"
    use strict;
    use warnings;
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
     
    $CGI::POST_MAX        = 1024 * 100;
    $CGI::DISABLE_UPLOADS = 1;
     
    # variables layout
    my $charset       = 'ISO-8859-1';
    my $lang          = 'fr';
    my $title         = 'Titre de ma page';
    my $distribution  = '';
    my $resource_type = '';
    my $description   = 'ma description';
    my $keywords      = 'dvp,olivier,regnier';
    my $shortcut_icon = '/favicon.ico';
    my $style_sheet   = '/css/feuille.css';
     
    my $cgi = new CGI;
     
    # skeleton layout
    print $cgi->header(
      -lang    => $lang,
      -charset => $charset,
      -head    => meta(
        { 'distribution'  => $distribution,
          'resource-type' => $resource_type,
          'description'   => $description,
          'keywords'      => $keywords,
        },
      ),
    );
    print $cgi->start_html(
      -title => $title,
      -style => { 'src' => $style_sheet },
    );
    print "Bonjour<br>\n";
     
    print $cgi->end_html;
    Voici le résultat :
    Code html : 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
    Head: <meta keywords="dvp,olivier,regnier" resource-type="" description="ma description" distribution="" />
    Lang: fr
    Content-Type: text/html; charset=ISO-8859-1
     
    <!DOCTYPE html
            PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
    <head>
    <title>Titre de ma page</title>
    <link rel="stylesheet" type="text/css" href="/css/feuille.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    Bonjour<br>
     
    </body>
    </html>

  9. #9
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    Je ne veux pas une feuille de style externe

    Exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    # css layout
    $style_sheet=<<END;
    <!--
    body {
    color:#000000;
    }
    -->
    END
    Ce n'est plus du tout la même chose

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'intégration CSS/Facelets
    Par titawine dans le forum JSF
    Réponses: 1
    Dernier message: 07/05/2012, 16h01
  2. Intégration CSS à JSP
    Par Marco88 dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 13/01/2011, 13h22
  3. css et cgi: source d'une boite?
    Par crapule dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 17/01/2008, 15h49
  4. Intégration css avec un script cgi
    Par Olivier Regnier dans le forum Web
    Réponses: 5
    Dernier message: 07/09/2007, 12h29

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