JavaScript and JSP

Discussions

Web tier: servlets, JSP, Web frameworks: JavaScript and JSP

  1. JavaScript and JSP (3 messages)

    From a .js file i am trying to create a reusable variable of a jsp function for example.
    Does anyone know how the js file can grab a jsp function from the jsp page for example trying something really simple.

    ++jsp page++
    <html>
    <head><title></title></head>
    <script SRC = 'mysource.js' language="JavaScript">
    <body>
    <import%@ java.util.Date" %>
    </body>
    </html>


    +++mysource.js+++
    //called when i need it through a javascript function on the jsp page
    function retrieveDate() {

    var dateStored = <%= new Date() %>

    }

    Threaded Messages (3)

  2. JavaScript and JSP[ Go to top ]

    Joey,

    I don't believe this will work. By using a js file your jsp will never get processed. Either place everything in your JSP, or create mysource.js as a JSP and use the JSP include tag instead, see below:

    --------------------

    ++jsp page++
    <html>
    <head><title></title></head>
    <%@ page import="java.util.Date" language="java" %>
    <%@ include file="mysource.jsp" %>
    <body>
    </body>
    </html>


    +++mysource.jsp+++
    //called when i need it through a javascript function on the jsp page
    function retrieveDate() {

    var dateStored = <%= new Date() %>

    }

    --------------------

    Does that help?

    Steve
  3. JavaScript and JSP[ Go to top ]

    I forgot one thing ... add the javascript tags to your mysource.jsp file so it looks like this:

    ----------

    +++mysource.jsp+++
    //called when i need it through a javascript function on the jsp page

    <script>

    function retrieveDate() {

    var dateStored = <%= new Date() %>

    }

    </script>

    ----------

    Steve
  4. thankx steve[ Go to top ]

    thankx for the information steve.
    Ofcourse We can do that. but I don't want to write javascript for any reason.instead How can i validate the object with jsp <% %>


    example: I want change the values of combo box two depending on the values select in other combo box one .

    can u help me to this