469,923 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

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="javascript" 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.
Jul 20 '05 #1
1 4467
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="text/javascript" %>
"Matthew Flower" <Ma********@yahoo.com> wrote in message
news:b7**************************@posting.google.c om...
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="javascript" 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.

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Patrick | last post: by
2 posts views Thread by Rose Girl | last post: by
6 posts views Thread by moongeegee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.