java javascript asp

I am trying to develop an application that will query a database
(which I now understand how to do.) The application has javascript rollover menus. What i would like to do is query the categories of the database and dynamically write the .js file for the javascript so that my mouseover menus will be dynamically created as the categories are added, I have been learning java and I thought that I would be able to write a java program that would query the db and then write a file with the .js extension or edit the file or something of the sort, is this a good way to do this or is there an easier way?!!! help!!!

Yes, you can do this using a jsp. If you want to have all your javascript in a separate .js file so all pages can easily import it, then you simply rename your .js to .jsp and add java code. You also need to change the content type of the jsp. Something like this:

this way I can use the asp variables inside the javascript that asp (or jsp for that matter) is writing. correct?

Yes.

Outputting a .js file in an asp is no different than outputting html in an asp. I assume an asp is the same as a jsp in the fact that if you are not in a script tag (<% %>) then the content is put out to the response. For instance:

Code:

<html>
<body>
<%
//this is in a jsp tag and would be processed server side
String someString = "this is a string";
%>
This is not in a script tag and would be output as html.
I can display the contents of the variable using <%= someString %>
<%
//I can also write to the response using the out stream
out.println("<b>this will be bold on the page</B>");
%>
</body>
</html>

ASP has some similar convention I am sure. To do a .js file, you are outputting javascript instead of html, but it works the exact same way. What you want is that when a browser receives the file, it is in the exact same format as if it called a static file. This make sense?

yes and this way the user can quickly navigate a javascript cascading menu to the product they want, which when clicked will send an "item id" to query a database(possible stored procedure) and return (the product name, a picture, shipping sizes ie:skid, or single) with an (option to "buy now!!") this will then (add to a cart) or whatever until all selections are made and then (credit info) and bam i'm done.