Serving a JavaScript file from a Servlet

M

Matthew Flower

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.
 
M

Mike

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" %>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top