Java Servlet & Javascript

K

kurdt.johnston

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
 
B

Bryce

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.
 
M

Matt Humphrey

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 (e-mail address removed) http://www.iviz.com/
 
J

Jarmo

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'?
 
R

Ryan Stewart

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
 
K

kurdt.johnston

Hi,

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

Thanks again,
Kurdt
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top