Java Servlet & Javascript

Discussion in 'Java' started by kurdt.johnston@gmail.com, Feb 24, 2005.

  1. Guest

    Hi,

    I am writing to ask if anybody knows, is it possible to get the value
    from a JavaScript variable and use this value in a Java Servlet?
    I have read up on this but all i have found is getting the JavaScript
    value through a form submit.

    What I need is:
    I have a html select combo box.
    I need to extract the selected value from this and use this value to
    query a database.

    Is this possible.

    Thanks in advance,
    Kurdt
    , Feb 24, 2005
    #1
    1. Advertising

  2. Bryce Guest

    On 24 Feb 2005 10:49:48 -0800, wrote:

    >Hi,
    >
    >I am writing to ask if anybody knows, is it possible to get the value
    >from a JavaScript variable and use this value in a Java Servlet?
    >I have read up on this but all i have found is getting the JavaScript
    >value through a form submit.
    >
    >What I need is:
    >I have a html select combo box.
    >I need to extract the selected value from this and use this value to
    >query a database.
    >
    >Is this possible.


    Doesn't this involve a form submit? How else would the server know
    what the value is? Javascript is a client side technology, it runs in
    the browser. A Java Servlet, on the other hand, is a Server based
    technology. it is run on the server, and its output is sent to the
    Browser.

    So, to do you want to do, you would need to submit the form to the
    servlet, and the servlet would grab the value from the submitted form.

    --
    now with more cowbell
    Bryce, Feb 24, 2005
    #2
    1. Advertising

  3. <> wrote in message
    news:...
    > Hi,
    >
    > I am writing to ask if anybody knows, is it possible to get the value
    > from a JavaScript variable and use this value in a Java Servlet?
    > I have read up on this but all i have found is getting the JavaScript
    > value through a form submit.
    >
    > What I need is:
    > I have a html select combo box.
    > I need to extract the selected value from this and use this value to
    > query a database.
    >
    > Is this possible.


    Yes, it's possible, but it doesn't really have anything to do with Java and
    your question may be better asked in the JavaScript newsgroup.

    An HTML web page does not interact with a Java servlet directly. Rather, it
    forms an HTTP request that contains parameters and fires this off. The
    result might be processed by a servlet or a cgi or any server-side
    component. The only way a Java servlet can get the parameter is if it's
    encoded in the form or page request. You must either do a form submit or
    something that sends an HTTP request (e.g. open a document, follow a link,
    load an image, etc.)

    JavaScript can be used to invoke a page request directly or via a form and
    this request can include the values of JavaScript variables.

    Cheers,
    Matt Humphrey http://www.iviz.com/
    Matt Humphrey, Feb 24, 2005
    #3
  4. Jarmo Guest

    <> wrote in message
    news:...
    >
    > I am writing to ask if anybody knows, is it possible to get the value
    > from a JavaScript variable and use this value in a Java Servlet?


    Do you mean 'applet' rather than 'servlet'?
    Jarmo, Feb 24, 2005
    #4
  5. Ryan Stewart Guest

    <> wrote in message
    news:...
    > Hi,
    >
    > I am writing to ask if anybody knows, is it possible to get the value
    > from a JavaScript variable and use this value in a Java Servlet?
    > I have read up on this but all i have found is getting the JavaScript
    > value through a form submit.
    >
    > What I need is:
    > I have a html select combo box.
    > I need to extract the selected value from this and use this value to
    > query a database.
    >
    > Is this possible.
    >

    The others have given you a quick rundown of client-side and server-side. Your
    options for getting from the client to the server are:
    1. append a parameter to a query string
    2. submit a value in a form
    3. use an XMLHttpRequest
    Ryan Stewart, Feb 25, 2005
    #5
  6. Guest

    Hi,

    Just wanted to thank all who replied.
    I ended up using XMLHttpRequest as suggested and it worked great.

    Thanks again,
    Kurdt

    Ryan Stewart wrote:
    > <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I am writing to ask if anybody knows, is it possible to get the

    value
    > > from a JavaScript variable and use this value in a Java Servlet?
    > > I have read up on this but all i have found is getting the

    JavaScript
    > > value through a form submit.
    > >
    > > What I need is:
    > > I have a html select combo box.
    > > I need to extract the selected value from this and use this value

    to
    > > query a database.
    > >
    > > Is this possible.
    > >

    > The others have given you a quick rundown of client-side and

    server-side. Your
    > options for getting from the client to the server are:
    > 1. append a parameter to a query string
    > 2. submit a value in a form
    > 3. use an XMLHttpRequest
    , Mar 1, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,396
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,876
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    1,978
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,827
  5. javadev
    Replies:
    5
    Views:
    12,851
    javadev
    Nov 16, 2006
Loading...

Share This Page