Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get Javascript values and use them in a servlet?

905759Dec 16 2011 — edited Dec 19 2011
Hey

I have a HTML which has Javascript scripts which I have to get values from (a array to be exact) and pass them to a servlet so I can process the information in a certain way. I cant seem to find a way to do this properly as the servlet is server side and Javascript is client side. How can I implement this?

Using a quick example example I have

C:/index.html
C:/js/script.js

Index.html contains:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="js/script.js">
</script>
</head>
<body>
a href="javascript:void(0);" id="add"><img src="images/menunew.png" alt="plus" border="0" />
/a>
</body>
</html>



Script.js contains:


var Script = Class.create({
a:4,
b:5,

add: function(){
return (this.a + this.b);
}
});

(Ignore syntaxis errors as this is a quick example I wrote up just to see if you can give me a practical example on how to read it.)

How can from a Java servlet access a and b from the script.js file (which contains a class named Script) and also access the function add which returns that value?

Thank you for the help

Edited by: 902756 on 16-dic-2011 0:18
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 16 2012
Added on Dec 16 2011
5 comments
3,963 views