简体   繁体   中英

Access of a member function of java object from javascript

Is there any possibility to call setter method of a Java object which is stored in the HTTP session in Javascript?

I managed to access getter like this:

var result='<%=((MyObject) portletSession.getAttribute("resultObj")).getValue() %>';

But I need set back this result after some modification in Javascript.

Is it possible, or should give up my idea?

It's not possible in the way you think it is.

It is important to realize that Javascript is executed in the browser after your server has finished running the Java process that sends back the content. There is no connection between code that runs in Javascript and your JVM process on the server - this code is running in two different places.

You are able to read Java session attributes in the Javascript when the server is generating the Javascript to send down the pipe to the user. But once the user's browser is executing the code, that code running on someone else's computer can't magically change values back on your server.

You'll want to look into sending asynchronous HTTP requests from the user's browser (in JavaScript) to your server.

No this is not possible.

Java runs and your server and javascript in your browser. there is no type of connection between those. you need some kind of service to call remote functions

Is there any possibility to call setter method of a java object which is stored in http session in javascript?

You cannot. java plays on server side and javascript on client side. So a big No .

But I need set back this result after some modification in javascript.

Again No .You need to make a server request in order to send some value to java.

It seems you need Asynchronous call . Learn Ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM