By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Serving a JavaScript file from a Servlet

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.