Serving a JavaScript file from a Servlet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Flower

    Serving a JavaScript file from a Servlet

    I'd like to generate a JavaScript file from a servlet. Mozilla 1.5
    seems to have no problem with this, but IE 6.0 is not cooperating.

    I've created a very simple test servlet that writes one line:
    alert("hello");

    I have an HTML page that looks like this:
    <html><head>
    <script language="javas cript" src="/servlet/Test"></script>
    </head></html>

    If I don't use the page, but instead use the URL for the script
    directly from my browser, in Mozilla the page comes up. (Normal
    Mozilla behavior - it displays the page rather than loading it.) In
    IE, I instead get an error message:

    Internet Explorer cannot download Test from localhost
    Internet Explorer was not able to open this Internet Site.
    The requested site is either unavailable or cannot be found.
    Please try again later.

    Does anyone have any idea why IE can't display the page? I've tried
    using a variety of MIME types (text/javascript, text/JScript,
    application/x-javascript) and nothing seems to work. One interesting
    note -- if I change the Mime type to text/html, the alert("hello")
    will show up if I am using the URL directly.

    Has anyone else done this? Please help, I'm out of ideas.
  • Mike

    #2
    Re: Serving a JavaScript file from a Servlet

    I have had no problem, however I point to a JSP file instead of a servlet
    and I use the following content type:
    <%@ page contentType="te xt/javascript" %>


    "Matthew Flower" <MattFlower@yah oo.com> wrote in message
    news:b7eeb682.0 312091712.1d415 967@posting.goo gle.com...[color=blue]
    > I'd like to generate a JavaScript file from a servlet. Mozilla 1.5
    > seems to have no problem with this, but IE 6.0 is not cooperating.
    >
    > I've created a very simple test servlet that writes one line:
    > alert("hello");
    >
    > I have an HTML page that looks like this:
    > <html><head>
    > <script language="javas cript" src="/servlet/Test"></script>
    > </head></html>
    >
    > If I don't use the page, but instead use the URL for the script
    > directly from my browser, in Mozilla the page comes up. (Normal
    > Mozilla behavior - it displays the page rather than loading it.) In
    > IE, I instead get an error message:
    >
    > Internet Explorer cannot download Test from localhost
    > Internet Explorer was not able to open this Internet Site.
    > The requested site is either unavailable or cannot be found.
    > Please try again later.
    >
    > Does anyone have any idea why IE can't display the page? I've tried
    > using a variety of MIME types (text/javascript, text/JScript,
    > application/x-javascript) and nothing seems to work. One interesting
    > note -- if I change the Mime type to text/html, the alert("hello")
    > will show up if I am using the URL directly.
    >
    > Has anyone else done this? Please help, I'm out of ideas.[/color]


    Comment

    Working...