views:

254

answers:

1

Hi guys,

I am newby in Spring, but have a task, and I am learning on the fly. I used Roo to generates for me part of the code, but now I have to make some dynamic list binding, which is done with form, popping-up in new window, and when the submit button is pushed I have to insert the new values in the parent window.

For the purpose I wrote a .js file, which hooks the values to the parent DOM tree, but the point is that I can't configure Spring to deliver the required .js file to the browser. The browser, doesn't recognize my function. Even when I try to access the .js file via the browser, I receive error that the file couldn't not be found.

I've tried to configure the web.xml, but it didn't work...

Any ideas, how I can configure the access to a .js file in a Spring MVC application?

Thanks a lot!

P.S. Respectively, I'll need to grant access for a static .htm(l) file... I suppose the principle for configuration of the access of static html files is the same..., right?

+1  A: 

You just need to get the path to the file right. Assuming you have a Maven-like set-up (I assume you do because you're using Roo), then your script belongs under src/main/webapp - probably in something like a scripts folder.

Let's assume that your file is at src/main/webapp/scripts/myscript.js

You can create a URL reference for your script by adding the following Spring tag:

<spring:url value="/scripts/myscript.js" var="script_url"/>

This should give you the right path to your script, regardless of the context in which you later decide to publish your webapp.

After that, it's just a matter of using that reference:

<script type="text/javascript" src="${script_url}"></script>
GaryF
Yes, I tried that. it doesn't work. again: "Sorry, we did not find the resource you were looking for."I put the script in my .jspx file, also put tried it WEB-INF/layouts/default.jspx (in order to be in the <head>), but it doesn't work...
shadrik
@shadrik: what I'm suggesting definitely works, so there must be something wrong with your deployment. Deploy your app on the server and find where your script is being deployed underneath that.
GaryF
thanks, I'll give it a try.
shadrik