#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    16

    using CGI/C++ to write a call for a CSS external file does not work


    Hi,

    I am using Apache server on Win 2000 and I have a CSS external file named estilos.css.

    The CGI/C++ script writes it to the HMTL page but the CSS does not format the tag.

    The code is pretty simple, but long, and this is the part that writes the CSS reference to the HMTL page:

    cout << "<link rel=\"stylesheet\" type=\"text/css\" href=\"estilos.css\"/>"
    << endl;

    Thanks in advance,
    Daniel

    --
    The code follows:

    class CppCGI {
    public:
    CppCGI( string = "" , string = "" );//construtor
    ~CppCGI();
    void ConstruirTopoHTML() const;//constrói topo da pagina HMTL
    void ConstruirBaixoHTML() const;//constroi parte de baixo da pagina HTML
    string getTitulo(){ return titulo; };
    string getTituloh(){ return tituloh;};
    protected:
    string titulo;//titulo da pagina
    string tituloh;//titulo a aparecer entre os tags <h1>
    };



    //***************************************************************
    CppCGI::CppCGI( string tit , string tith ){
    cout << "Content-Type: text/html\n\n" << endl;
    titulo = tit;
    tituloh = tith;
    }

    CppCGI::~CppCGI(){}

    void CppCGI::ConstruirTopoHTML() const{


    cout <<"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""
    << "\"http://www.w3.org/TR/html4/loose.dtd\">" << endl;


    cout << "<html>"<< endl;
    cout << "<head>"<< endl;


    cout << "<title>" + titulo + "</title>" << endl;
    cout << "</head>" << endl;

    cout << "<body>" << endl;

    cout << "<link rel=\"stylesheet\" type=\"text/css\" href=\"estilos.css\"/>"
    << endl;

    }

    void CppCGI::ConstruirBaixoHTML() const {

    cout << "</body>" << endl;
    cout << "</html>";

    }


    int main()
    {

    CppCGI * html = new CppCGI ( "Pagina EM CGI", "CGI e C++");

    html->ConstruirTopoHTML();

    cout<< "<p> Deu certo? </p>";

    html->ConstruirBaixoHTML();

    delete html;

    return 0;

    }
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    248
    Capture the output of the script and see if your resultant HTML works properly when opened as a plain HTML file. If not (as I suspect), then diagnosing that will likely show you what the problem is in your C++ code. Remember, garbage in, garbage out.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    16
    Originally Posted by mitakeet
    Capture the output of the script and see if your resultant HTML works properly when opened as a plain HTML file. If not (as I suspect), then diagnosing that will likely show you what the problem is in your C++ code. Remember, garbage in, garbage out.
    Nopes, the HTML is displayed correct.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Pagina EM CGI</title>
    </head>
    <body>
    <link rel="stylesheet" type="text/css" href="estilos.css"/>
    <p> Deu certo? </p></body>
    </html>

    Which presents a non formated window:

    Deu certo?

    as it follows attached.
    Attached Images
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    248
    Well, you got me! I have done very little work with style sheets, but my understanding it it is all happening on the browser end and the server has nothing to do with it. Have you tried it in other browsers? Perhaps you are sending the header wrong somehow (though it sure looks fine to me) and the browser is interpreting it as plain text or something. I have done this sort of thing in the past so I know it is possible.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    16
    Originally Posted by mitakeet
    Well, you got me! I have done very little work with style sheets, but my understanding it it is all happening on the browser end and the server has nothing to do with it. Have you tried it in other browsers? Perhaps you are sending the header wrong somehow (though it sure looks fine to me) and the browser is interpreting it as plain text or something. I have done this sort of thing in the past so I know it is possible.
    Yeah man, I always put style sheets includes in regular HTML pages. The browser simply reads the reference and applies the format. I thought I simply had to write a string to the HMTL , but it looks like the browser (either IE or Mozilla) can't interpret it if it was written from a CGi script.

    So, as the HTML 4.01 and th XHTML specs say "don't use formats in HTML tags" I am lost. I will try to figure it out.

    Thanks a lot anyway!
    Daniel
    Last edited by Danbr; February 18th, 2004 at 10:38 AM. Reason: mistakes
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    1
    Rep Power
    0
    your link seems to be incorrect. If your .css file is in your htdocs/html directory and the .cgi file is in the cgi-bin directory then you need to write it as "../estilos.css"

    let me know if this helped.

    Best regards.
  12. #7
  13. Thanks Johnny Hart (BC) R.I.P.

    Join Date
    May 2003
    Location
    Dallas
    Posts
    5,262
    Rep Power
    1960
    <link rel="stylesheet" type="text/css" href="estilos.css"/>
    That belongs in the head, not in the body.

    cheers,

    gary
    There are those who manage to build a web site without knowing what they're doing; thereby proving to themselves they do, indeed, know what they're doing.

    My html and css workshop, demos and tutorials.
    Ask a better question, get a better answer.

IMN logo majestic logo threadwatch logo seochat tools logo