Javascript In A Servlet??

Discussion in 'Java' started by Steve Burrus, May 6, 2004.

  1. Steve Burrus

    Steve Burrus Guest

    Can anyone please tell me if some JavaScript is allowed in the html
    content of a Java Servlet or not???!! I have tried to get an alert
    dialogue box to pop up when the servlet is first loaded into my browser,
    but have failed to do so!!
     
    Steve Burrus, May 6, 2004
    #1
    1. Advertising

  2. Steve Burrus wrote:

    > Can anyone please tell me if some JavaScript is allowed in the html
    > content of a Java Servlet or not???!! I have tried to get an alert
    > dialogue box to pop up when the servlet is first loaded into my browser,
    > but have failed to do so!!


    Show us your code. You can generate any kind of content with a Servlet, be
    it an image, HTML,XML, HTML with javascript, ...

    If it doesn't work, the problem is probably your content, not the servlet
    itself.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, May 6, 2004
    #2
    1. Advertising

  3. Steve Burrus

    Sudsy Guest

    Steve Burrus wrote:
    > Can anyone please tell me if some JavaScript is allowed in the html
    > content of a Java Servlet or not???!! I have tried to get an alert
    > dialogue box to pop up when the servlet is first loaded into my browser,
    > but have failed to do so!!
    >


    Just for clarification, a servlet is NEVER loaded into your browser.
    Think about it: a servlet runs on the server side!
    Perhaps you could explain what you're trying to do, what you've
    already attempted, and what you expect to happen?
     
    Sudsy, May 6, 2004
    #3
  4. On Thu, 06 May 2004 21:19:26 GMT, Steve Burrus wrote:

    > ...I have tried to get an alert
    > dialogue box to pop up when the servlet is first loaded into my browser,
    > but have failed to do so!!


    Does the JS work from HTML, Steve?

    Often the problem is the JS, beyond anything else.

    Of course, the best way to investigate that
    is to take it up with the Gurus of JavaScript.
    You can get a good link from here..
    <http://www.physci.org/codes/javafaq.jsp#js>

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 7, 2004
    #4
  5. Steve Burrus

    Liz Guest

    "Steve Burrus" <> wrote in message
    news:yZxmc.24749$...
    > Can anyone please tell me if some JavaScript is allowed in the html
    > content of a Java Servlet or not???!! I have tried to get an alert
    > dialogue box to pop up when the servlet is first loaded into my browser,
    > but have failed to do so!!
    >


    The output of the servlet is just text sent to the browser
    so you can spit out anything. The browser would have to
    have javascript enabled for it to work.
     
    Liz, May 7, 2004
    #5
  6. Steve Burrus

    Steve Burrus Guest

    "Sudsy", I am just simply trying/attempting to write a simple
    "HelloServlet.java" or maybe a "WelcomeServlet.java"-if you know what
    that is!

    I am using a series of "out.println()" methods within the
    "<html><body>" tags of the servlet! I would like to be able to see a
    JavaScript "alert" dialog box pop up when the html page is first loaded
    into my personal web browser!! (Wait a minute, just now I thought of a
    possible solution for my problem, and that is to put the javascript that
    I wanna work with into the <html> file that is supposed to work with the
    servlet.) Am I am on the right track with this kind of thinking or
    not??? And finally, how much experience do you have with working with
    servlets anyway? And the "companion" question to that, what are the
    app.servers that you have worked with??

    ****************************************************************************

    Sudsy wrote:
    > Steve Burrus wrote:
    >
    >> Can anyone please tell me if some JavaScript is allowed in the html
    >> content of a Java Servlet or not???!! I have tried to get an alert
    >> dialogue box to pop up when the servlet is first loaded into my
    >> browser, but have failed to do so!!
    >>

    >
    > Just for clarification, a servlet is NEVER loaded into your browser.
    > Think about it: a servlet runs on the server side!
    > Perhaps you could explain what you're trying to do, what you've
    > already attempted, and what you expect to happen?
    >
     
    Steve Burrus, May 7, 2004
    #6
  7. Steve Burrus

    Steve Burrus Guest

    Okay Christophe, here is my servlet code, and I must tell you it just
    now compiled for me successfully! :

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;

    public class WelcomeServlet extends HttpServlet {

    // process "get" requests from clients
    protected void doGet( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    {
    response.setContentType( "text/html" );
    PrintWriter out = response.getWriter();

    // send XHTML page to client

    // start XHTML document
    out.println( "<?xml version = \"1.0\"?>" );

    out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
    "XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
    "/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );

    out.println(
    "<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

    // head section of document
    out.println( "<head><JavaScript version='1.3'>" );
    out.println( "<title>A Simple Servlet Example</title>" );
    out.println( "</head></javascript>" );

    // body section of document
    out.println( "<body onLoad=alert('I am FLYING HIGH with this Servlet')>" *
    out.println( "<h1>Welcome to Servlets!</h1>" );
    out.println( "</body>" );

    // end XHTML document
    out.println( "</html>" );
    out.close(); // close stream to complete the page
    }
    }

    * Just to note that I have all of the content of that alert box on ONE
    line in my code, "text wrap" doesn't work too well in my email
    composition window.



    Christophe Vanfleteren wrote:

    > Steve Burrus wrote:
    >
    >
    >> Can anyone please tell me if some JavaScript is allowed in the html
    >> content of a Java Servlet or not???!! I have tried to get an alert
    >> dialogue box to pop up when the servlet is first loaded into my
    >> browser, but have failed to do so!!

    >
    >
    > Show us your code. You can generate any kind of content with a
    > Servlet, be it an image, HTML,XML, HTML with javascript, ...
    >
    > If it doesn't work, the problem is probably your content, not the
    > servlet itself.
    >
     
    Steve Burrus, May 7, 2004
    #7
  8. On Fri, 07 May 2004 20:48:32 GMT, Steve Burrus wrote:

    > // head section of document


    This is a badly malformed head

    > out.println( "<head><JavaScript version='1.3'>" );


    out.println( "<head>" );
    out.println( "<script language='javascript' type='text/javascript'>" );
    out.println( "<!-- //JavaScript goes here! -->" );
    out.println( "<!-- //important to end the script -->" );
    out.println( "</script>" );

    > out.println( "<title>A Simple Servlet Example</title>" );
    > out.println( "</head></javascript>" );


    out.println( "</head>" );

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 7, 2004
    #8
  9. Steve Burrus

    Steve Burrus Guest

    Okay Andrew, I tried out your code which u supplied me with, but alas, I
    still didn't get my desired alert dialogue box to pop up at all!!! Here
    is the code which I had (which again compiled okay!) :


    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;

    public class WelcomeServlet extends HttpServlet {

    // process "get" requests from clients
    protected void doGet( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    {
    response.setContentType( "text/html" );
    PrintWriter out = response.getWriter();

    // send XHTML page to client

    // start XHTML document
    out.println( "<?xml version = \"1.0\"?>" );

    out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
    "XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
    "/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );

    out.println(
    "<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

    // head section of document

    out.println( "<head>" );
    out.println( "<script language='javascript' type='text/javascript'>" );
    out.println("alert('I am FLYING HIGH\n\n with this Servlet!!')");
    out.println( "</script>" );
    out.println( "</head>" );
    // body section of document
    out.println( "<body>");
    out.println( "<h1>Welcome to Servlets!</h1>" );
    out.println( "</body>" );

    // end XHTML document
    out.println( "</html>" );
    out.close(); // close stream to complete the page
    }
    }




    Andrew Thompson wrote:
    > On Fri, 07 May 2004 20:48:32 GMT, Steve Burrus wrote:
    >
    >
    >> // head section of document

    >
    >
    > This is a badly malformed head
    >
    >
    >> out.println( "<head><JavaScript version='1.3'>" );

    >
    >
    > out.println( "<head>" );
    > out.println( "<script language='javascript' type='text/javascript'>" );
    > out.println( "<!-- //JavaScript goes here! -->" );
    > out.println( "<!-- //important to end the script -->" );
    > out.println( "</script>" );
    >
    >
    >> out.println( "<title>A Simple Servlet Example</title>" );
    >> out.println( "</head></javascript>" );

    >
    >
    > out.println( "</head>" );
    >
    > HTH
    >
     
    Steve Burrus, May 8, 2004
    #9
  10. Steve Burrus

    Sudsy Guest

    Steve Burrus wrote:
    > "Sudsy", I am just simply trying/attempting to write a simple
    > "HelloServlet.java" or maybe a "WelcomeServlet.java"-if you know what
    > that is!
    >
    > I am using a series of "out.println()" methods within the
    > "<html><body>" tags of the servlet! I would like to be able to see a
    > JavaScript "alert" dialog box pop up when the html page is first loaded
    > into my personal web browser!! (Wait a minute, just now I thought of a
    > possible solution for my problem, and that is to put the javascript that
    > I wanna work with into the <html> file that is supposed to work with the
    > servlet.) Am I am on the right track with this kind of thinking or
    > not??? And finally, how much experience do you have with working with
    > servlets anyway? And the "companion" question to that, what are the
    > app.servers that you have worked with??


    Okay, so I don't usually reply to flame-bait but I'll make an
    exception this time. App Servers: Oracle 9i, BEA WebLogic and
    IBM WebSphere. Servlet experience: more than 5 years, developing
    on various platforms, deploying to others. Check out some of my
    articles here:
    <http://www.sudsy.net>
    Click on the "Technology" button and take away from it what
    you will...
    And if you'll read and consider what other helpful people have
    posted, you might comprehend why I posted as I did. Content
    type is crucial to interpretation of the body and any embedded
    content (such as images et al).
    Fair enough?
     
    Sudsy, May 8, 2004
    #10
  11. Steve Burrus

    Steve Burrus Guest

    "sudsy", I am just a little bit curious about what you mean by
    "flame-bait" from me!! Anyway, you say that u have worked with the
    "Websphere" and the "WebLogic" servers respectively. I have recently
    gotten/obtained both of those application servers again, since I have
    had them in the past, but alas, I haven't really ever gotten a "handle"
    on just how exactly one goes about starting to use them for J2EE
    development!!

    Can you please, please tell me FINALLY how you go about using them for
    deploying such components of the j2ee as servlets, jsp's, and even ejb's???!

    ************************************************************************************************


    Sudsy wrote:
    > Steve Burrus wrote:
    >
    >> "Sudsy", I am just simply trying/attempting to write a simple
    >> "HelloServlet.java" or maybe a "WelcomeServlet.java"-if you know what
    >> that is!
    >>
    >> I am using a series of "out.println()" methods within the
    >> "<html><body>" tags of the servlet! I would like to be able to see a
    >> JavaScript "alert" dialog box pop up when the html page is first
    >> loaded into my personal web browser!! (Wait a minute, just now I
    >> thought of a possible solution for my problem, and that is to put the
    >> javascript that I wanna work with into the <html> file that is
    >> supposed to work with the servlet.) Am I am on the right track with
    >> this kind of thinking or not??? And finally, how much experience do
    >> you have with working with servlets anyway? And the "companion"
    >> question to that, what are the app.servers that you have worked with??

    >
    >
    > Okay, so I don't usually reply to flame-bait but I'll make an
    > exception this time. App Servers: Oracle 9i, BEA WebLogic and
    > IBM WebSphere. Servlet experience: more than 5 years, developing
    > on various platforms, deploying to others. Check out some of my
    > articles here:
    > <http://www.sudsy.net>
    > Click on the "Technology" button and take away from it what
    > you will...
    > And if you'll read and consider what other helpful people have
    > posted, you might comprehend why I posted as I did. Content
    > type is crucial to interpretation of the body and any embedded
    > content (such as images et al).
    > Fair enough?
    >
     
    Steve Burrus, May 8, 2004
    #11
  12. Steve Burrus wrote:

    > "sudsy", I am just a little bit curious about what you mean by
    > "flame-bait" from me!! Anyway, you say that u have worked with the
    > "Websphere" and the "WebLogic" servers respectively. I have recently
    > gotten/obtained both of those application servers again, since I have
    > had them in the past, but alas, I haven't really ever gotten a "handle"
    > on just how exactly one goes about starting to use them for J2EE
    > development!!
    >
    > Can you please, please tell me FINALLY how you go about using them for
    > deploying such components of the j2ee as servlets, jsp's, and even
    > ejb's???!


    How about you read the docs of your specific server, and then ask a question
    when you have a specific problem. One can't just answer your question here,
    since the deployment process is partly different for all the appservers.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, May 8, 2004
    #12
  13. On Fri, 07 May 2004 23:06:12 GMT, Steve Burrus wrote:

    [ Comments all the way to bottom ]

    > Okay Andrew,


    (sighs) OK Steve.. I will give you one last chance.

    Please stop top-posting.
    <http://www.physci.org/codes/javafaq.jsp#netiquette>

    > ...I tried out your code which u supplied me with, but alas, I
    > still didn't get my desired alert dialogue box to pop up at all!!! Here
    > is the code which I had (which again compiled okay!) :


    It is important realise this Steve.

    Java code that compiles does *not* produce
    valid HTML/XHTML/JavaScript..

    Whether the latter is 'valid and well formed'
    an entirely separate matter.

    The stuff you produced, was not valid if it
    had been typed in notepad. So writing it
    using Java is not going to fix it.

    [[ If you want a JS alert, it is best to
    do it all in HTML first. ]]

    This is something that a lot of Java
    programmers get wrong.

    That is how I develop my sites - I work out
    the HTML/JS/applet calls in a web page ..THEN,
    once it is working and valid, I write more
    advanced page(s) generated by the server.

    If I mess with 3 technologies at once
    (e.g. Java/HTML/JS) I stuff it up.

    > import javax.servlet.*;
    > import javax.servlet.http.*;


    So I shouldn't have to be looking at this crap.

    This should have _nothing_ to do with servlets yet.

    Which ultimately means you should be
    asking THIS question on...
    <http://google.com/groups?group=comp.lang.javascript>

    As it happens I need to pop in there myself
    to get some help with a URL/parameters problem,
    so I might be seeing you there.

    Now, I considered sitting down and writing
    a simple HTML/JS pop-up example for youm
    but neither do I have time, nor is it fair to
    the other members if this Java group.

    What I recommend is. Mosey on over to c.l.js
    and you will have working HTML/JS in 20 minutes.
    Then write that back into your servlet.

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 8, 2004
    #13
  14. Steve Burrus

    Roedy Green Guest

    On Sat, 08 May 2004 08:09:22 GMT, Andrew Thompson
    <> wrote or quoted :

    >Please stop top-posting.

    It does not matter for God's sake. You have no right to impose how
    people speak any more that what they speak.

    If you want to natter about something, what does matter is twits who
    quote pages of text irrelevant to their posts.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 8, 2004
    #14
  15. On Sat, 08 May 2004 08:20:44 GMT, Roedy Green wrote:
    > On Sat, 08 May 2004 08:09:22 GMT, Andrew Thompson


    >>Please stop top-posting.


    > It does not matter for God's sake.


    It does to me. (People are different)

    >..You have no right to impose how
    > people speak any more that what they speak.


    Which is why I said 'please'.

    The implication was 'stop top-posting or
    _I_ will no longer respond to your posts'.
    No more, no less.

    > If you want to natter about something, what does matter is twits who
    > quote pages of text irrelevant to their posts.


    I agree with you. I also comment on poor trimming.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 8, 2004
    #15
  16. Steve Burrus

    Sudsy Guest

    Steve Burrus wrote:
    > "sudsy", I am just a little bit curious about what you mean by
    > "flame-bait" from me!! Anyway, you say that u have worked with the
    > "Websphere" and the "WebLogic" servers respectively. I have recently
    > gotten/obtained both of those application servers again, since I have
    > had them in the past, but alas, I haven't really ever gotten a "handle"
    > on just how exactly one goes about starting to use them for J2EE
    > development!!
    >
    > Can you please, please tell me FINALLY how you go about using them for
    > deploying such components of the j2ee as servlets, jsp's, and even
    > ejb's???!


    Unfortunately, there's not a single definitive source. I've purchased
    numerous books on the separate elements (EJBs, JSPs, etc.) and worked
    through the provided examples. When it comes to deployment, that's
    very much a detail of the particular implementation. WebSphere, for
    example, uses a script called assembly.sh. Once I learned the format
    of the deployment files (ibm-ejb-jar-bnd.xmi and ibm-ejb-jar-ext.xmi)
    then I was able to generate them automatically in my build script. I
    also generate weblogic-ejb-jar.xml for deployment to WebLogic.
    But then you have to know the format of ears and wars as well so that
    you can put the files in the appropriate locations...
    There's a heck of a lot to learn and I don't know of any shortcuts.
     
    Sudsy, May 8, 2004
    #16
  17. Steve Burrus

    Steve Burrus Guest

    Please forgive my dumb ignorance, but what the hell is "Top Posting"
    anyway??!! Is it something that I shouldn't do??!

    ************************************************************************************************

    Roedy Green wrote:
    > On Sat, 08 May 2004 08:09:22 GMT, Andrew Thompson
    > <> wrote or quoted :
    >
    >
    >>Please stop top-posting.

    >
    > It does not matter for God's sake. You have no right to impose how
    > people speak any more that what they speak.
    >
    > If you want to natter about something, what does matter is twits who
    > quote pages of text irrelevant to their posts.
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Steve Burrus, May 8, 2004
    #17
  18. On Sat, 08 May 2004 19:48:51 GMT, Steve Burrus wrote:

    > Please forgive my dumb ignorance, but what the hell is "Top Posting"
    > anyway??!!


    Steve, do you understand th concept of links?

    They are those long blue things in
    your newsreader. They turn a much warmer
    purply red once you click on them, but I
    expect all yours are still that cold blue,
    'cos you do not seem to follow the links
    I give you.

    They are wonderful things, these links,
    they attach to information. I have for
    example, given you the link to the
    information on top-posting before..

    Here it is again.
    <http://www.physci.org/codes/javafaq.jsp#netiquette>

    >..Is it something that I shouldn't do??!


    What you should or shouldn't do is up to
    you Steve, and whether other people in the
    forum care any which way is up to them.

    You can choose to continue acting as you please,
    and the others in the forum can choose to help you,
    _or_ they can choose to ignore you ..or 'plonk' you,
    which is far worse.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 8, 2004
    #18
  19. Steve Burrus

    Sudsy Guest

    Steve Burrus wrote:
    > Please forgive my dumb ignorance, but what the hell is "Top Posting"
    > anyway??!! Is it something that I shouldn't do??!


    Top posting is what you've been doing. It's where you reply to a post
    and put new content at the top. Note that I'm doing the opposite,
    namely leaving the essence of your post at the top of the reply and
    adding my comments at the bottom. (I'm also trimming extraneous
    content.)
    It's just the standard way things are done on usenet groups. You want
    to leave just enough content so that people can follow the thread of
    conversation. If you go back and read Andrew's post you'll notice
    that he included a link (most newsreaders will make it "clickable")
    to a document describing what is called "netiquette".
    Andrew has some other good ideas as well, providing links to help
    you create a "short, self-contained, compilable example". Having one
    can considerably improve your chances of receiving helpful responses.
    If one can "cut" the code from the post and "paste" into a local file
    then it's easier to compile and test.
    You'll get used to it in time. People are actually trying to help you
    out here.
     
    Sudsy, May 8, 2004
    #19
  20. Steve Burrus

    Roedy Green Guest

    On Sat, 08 May 2004 19:48:51 GMT, Steve Burrus <>
    wrote or quoted :

    >Please forgive my dumb ignorance, but what the hell is "Top Posting"
    >anyway??!! Is it something that I shouldn't do??!


    It just means putting your response at the top and the stuff the
    other guy said that everyone has already read already underneath.

    It irritates some people. They like reading the same old stuff over
    and over and paging down 10 pages to get to where you say,
    "I agree".

    I consider it preferable. However, most people don't. I have
    proposed technology to deal with the problem but no one is interested.

    See http://mindprod.com/projmailreadernewsreader.html

    In the meantime, to keep Andrew happy, put your comment under the text
    it refers to, and to keep me happy, don't quote anything unless is
    very relevant. If the user wants to refer back, let him hit up arrow.
    You need just enough recall the gist of the other's argument.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 9, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,452
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,951
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,094
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,975
  5. DiscoStu
    Replies:
    0
    Views:
    533
    DiscoStu
    Jul 8, 2004
Loading...

Share This Page