Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript error produced using <script .....src=name.js></script>

Status
Not open for further replies.

Allain68

Programmer
Jul 2, 2004
2
GB
I am using Struts 1.1, Tomcat 4.1.12 on Windows XP
I am trying to add some JavaScript to a JSP page To do this I am including one or many JavaScript source files using the following style;

<script language="JavaScript" src="/pages/templates/code.js"></script>
<script type="text/JavaScript" src="/pages/templates/data.js"></script>

Directory structure Webapps/App/WEB-INF/pages etc

When I try to call a function in these sources, the function fails with the error message that the function is undefined.

If I take the source out of these files and put it in the JSP pages within a single

<script language="JavaScript" > ... all the code form code.js and data.js ...</script>

tags the issue is resolved, although this is to messy for my liking.

I have been checking the forums but this seems not to make sense as the former is supposed to work.
Have you experienced anything like this? or can you think of some reason that the system behaves like this?

I have tried to put these between the <Head> tags and elsewhere with the same result.

I have also tried this from HTML pages and they are served properly with the code executing on the browser.

An entry for js files is present in my web.xml file.

- <mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>
 
Sorted, it was a bit dumb.
The .js files were held below the WEB-INF directory, and everything below there is protected.
I have moved the files to a new JavaScript directory just under the app directory and set
<script language="JavaScript" src= "/APP/JavaScript/code.js"></script>and it it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top