Background:
I have a servlet in which I dynamically generate javascript and put in a variable script. Then I set the content type of the response as I text/javascriptsend the script to the client:
resp.setContentType("text/javascript");
resp.getWriter().println(script);
Problem:
The browser loads the javascript file, but does not recognize the functions inside the file. If I create a static javascript file and use it instead, it works fine.
Question:
What needs to be done for the browser to treat the servlet response as a regular javascript file?
Thank you for your help.
source
share