Sending Javascript values to a Java servlet using DWR?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Sending Javascript values to a Java servlet using DWR?

riahc3
This post was updated on .
Hey

I have a program in retrieving data from a HTML page with Javascript using Java. Lets say I have the structure of

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>


the script.js file contains:


var Script = Class.create({
a:4,
b:5,
add: function()
{
        return (this.a + this.b);  
}
});

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? I think DWR can help me out (alot) as its purpose is to help out comunication between Java and Javascript.


(Note that the code I just wrote might be incorrect as I wrote it quickly just to demostrate whats my problem)

This is driving me crazy as I have tried with Map (in Java) and retrieve it thru request but nothing. There isnt any way I see right now.

Thanks for the help.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sending Javascript values to a Java servlet using DWR?

david@butterdev.com
Hello,
   This is a generic response designed to help people who may not have seen or followed the directions/documentation on our site. 

Please start with our Quick Start:
http://directwebremoting.org/dwr/introduction/getting-started.html

If you have already went through the Quick Start and are still having difficulties please see our Troubleshooting page:
http://directwebremoting.org/dwr/support/common_problems.html

If you are still having problems you can search the DWR Users mailing list (http://dwr.2114559.n2.nabble.com/DWR-Users-f2114559.html) to see if someone has had and resolved a similar issue.  The final step is submitting a question to the DWR Users mailing list (http://directwebremoting.org/dwr/support/index.html#mailing_lists).

It is very important when sending messages to the list that you:
  1. Provide us with the version of DWR you are using and any relevant information on your environment/configuration.
  2. Provide us with relevant snippets of your code and configuration.  Generally sending us a small snippet of the JavaScript you are using to make your remote call, the signature of the Java method you are remoting, and small snippets of your DWR configuration are sufficient.
  3. Provide us with as much detail as possible.  You should have gathered plenty of information from the "Troubleshooting" page.  The more information you can share (server logs, results from DWR test page, information gathered while debugging your JavaScript or Java, etc.) the easier it will be for us to help you.
Thank you
DWR Team

On 12/16/2011 01:49 AM, riahc3 wrote:
Hey

I have a program in retrieving data from a HTML page with Javascript using
Java. Lets say I have the structure of

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

index.html contains:


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;       
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;>

<html>
<head>
 </head><body>    
<a class="moz-txt-link-freetext" href="javascript:void(0)">javascript:void(0); 
images/menunew.png 

</body>
</html>


the script.js file contains:


var Script = Class.create({
a:4,
b:5,
add: function()
{
        return (this.a + this.b);  
}
});

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? I think DWR can help me out (alot) as its purpose is to
help out comunication between Java and Javascript. 


(Note that the code I just wrote might be incorrect as I wrote it quickly
just to demostrate whats my problem)

This is driving me crazy as I have tried with Map (in Java) and retrieve it
thru request but nothing. There isnt any way I see right now.

Thanks for the help.

--
View this message in context: http://dwr.2114559.n2.nabble.com/Sending-Javascript-values-to-a-Java-servlet-using-DWR-tp7100070p7100070.html
Sent from the DWR - Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sending Javascript values to a Java servlet using DWR?

Mike Wilson
Administrator
In reply to this post by riahc3
As David says, it is not really clear what you want to do, or
if it has any relevancy to DWR. One interpretation is that you
want to execute local JavaScript and pass the value over to
Java without any HTTP request involved. In that case you
should rather look at the Rhino JavaScript engine or libraries
that build upon it.

Best regards
Mike Wilson

riahc3 wrote:

> Hey
>
> I have a program in retrieving data from a HTML page with
> Javascript using
> Java. Lets say I have the structure of
>
> C:/index.html
> C:/js/script.js
>
> index.html contains:
>
>
> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01
> Transitional//EN&quot;      
> &quot;http://www.w3.org/TR/html4/loose.dtd&quot;>
>
> <html>
> <head>
>  </head><body>    
> javascript:void(0);
> images/menunew.png
>
> </body>
> </html>
>
>
> the script.js file contains:
>
>
> var Script = Class.create({
> a:4,
> b:5,
> add: function()
> {
>         return (this.a + this.b);  
> }
> });
>
> 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? I think DWR can help me out (alot) as its
> purpose is to
> help out comunication between Java and Javascript.
>
>
> (Note that the code I just wrote might be incorrect as I
> wrote it quickly
> just to demostrate whats my problem)
>
> This is driving me crazy as I have tried with Map (in Java)
> and retrieve it
> thru request but nothing. There isnt any way I see right now.
>
> Thanks for the help.
>
> --
> View this message in context:
> http://dwr.2114559.n2.nabble.com/Sending-Javascript-values-to-
> a-Java-servlet-using-DWR-tp7100070p7100070.html
> Sent from the DWR - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sending Javascript values to a Java servlet using DWR?

riahc3
I was wondering if DWR would help me in this case make it easier or not.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sending Javascript values to a Java servlet using DWR?

Mike Wilson
Administrator
DWR can do what you ask, but the way you are asking it makes me
think you would be better served with just a JavaScript engine.

With DWR you can access JavaScript through Reverse Ajax using
the following chain:

Java -> DWR -> servlet -> HTTP    -> web    -> browser  -> JS
code           app        Rev Ajax   browser   JS engine   code

If all you want to do is to access some JavaScript from Java,
and don't need a web solution, then the following is much
simpler:

Java -> Rhino JS -> JS
code    engine      code

riahc3 wrote:
> I was wondering if DWR would help me in this case make it
> easier or not.

Loading...