#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0

    Unhappy 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!!!
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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:

    Code:
    <% response.setContentType("application/x-javascript"); %>
    
    var someString = "<%= someJavaVariable %>";
    
    function getString() {
      return someString;
    }
    
    ... other code ...
    EDIT: this is assuming you know servlets/jsp. If you don't then you have a steep learning curve ahead to do what you want to do.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0
    thanks, i also know some asp and sql , maybe i could do it with asp?
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I do not know ASP, but I would think the steps would be virtually identical.

    Make an asp. In it set the content type to what I described. Make sure and use the .asp extension for your file. In your html you would use a url like this to import your javascript:

    <script src="nameOfYourFile.asp">
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0
    instead of <script src="blah.js">

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

    i could just make my db connection at the top of the script


    //********************************

    dim vars
    set var to server.createobject(connection)
    get record set

    and then what?
    just write in javascript?
    or do i have to use response.write and all that?

    thanks again!!

    with a little help I think i can do this, I hope
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    instead of <script src="blah.js">

    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?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0
    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.

    Its a lot to grasp!!!

IMN logo majestic logo threadwatch logo seochat tools logo