Background:
I have a servlet in which I am dynamically generating javascript and putting into a variable script. Then I set the response content type as text/javascript and send the script over to the client:
resp.setContentType("text/javascript");
resp.getWriter().println(script);
Problem:
The browser does download the javascript file but it doesn't recognize the functions inside the file. If I create a static javascript file and use it instead, it works fine.
Question:
What should be done so that browser treats response from the servlet as a regular javascript file?
Thank you for help.

Content-Typeheader being received by clients? I've had situations where resource managers/VIPs/reverse proxies would rewrite my carefully crafted headers and inject all sorts of rule-based junk in them. If so, try ending the servlet mapping with.js. Mentioning the browser, servlet container, etc. might help.