Hello everyone,

I have a question for you.

I would like to call a function situated on a server side servlet or in a jsp file with a javascript function (client side) and to show the results returned by the servlet's function.

Do you have any ideas?

yes. I have tons of ideas.

And no, what you're thinking of doing isn't going to work (at least not in the way you probably think to do it).

You know, you have the same kind of thing in Ajax the only difference is that I don't want to call a servlet or a jsp page but only some functions situated in the servlet or jsp page.

like I said, you don't realise what you're dealing with here.

What you're effectively saying is that you want to call private method on a class without having access to an instance of that class.
Even if you had an instance you'd be hard pressed to call that method (there are ways, but they're only for experts).

Think of trying to use the car stereo in the car of someone in another country to listen, from your own bedroom, to a CD that's sitting on your neighbour's kitchen table who's on vacation and you don't have the key to his door.
And oh, that car stereo doesn't have a CD player and the car is turned off so the stereo has no power.

> I would like to call a function situated on a server side servlet or in
> a jsp file with a javascript function (client side) and to show the
> results returned by the servlet's function.
Any reason for this weird requirement. There is as such no problem which requires you to do such a thing. Use normal AJAX calls and you would be a happy man.

I have finally resolved my problem using dojo, a javascript plateform used in Ajax development.

Dojo is really great and you can do whatever you want with it (almost) I'm passing in the javascript request the name of the function I want to call on the server side and on the servlet I'm doing a compareTo and I'm calling the required function.

After you just use a JSONObject to send data to the client and once you have your data on the client side you put it where you want in your html tags and that's all.


Thank you for all your answers


ciao


ovidiu

Comments
Good luck.

> I want to call on the server side and on the servlet I'm doing a compareTo and I'm calling the
> required function.

Let me guess, you pass a string which would probably be the name or the code of the function which you want to call in the servlet. This string is received by the goGet() or doPost() method of this servlet which then uses a bunch of if..else statements to decide what is the code passed from the client side and then decides which function has to be executed. Isn't it?

Glad you could figure it out. :-)

> I want to call on the server side and on the servlet I'm doing a compareTo and I'm calling the
> required function.

Let me guess, you pass a string which would probably be the name or the code of the function which you want to call in the servlet. This string is received by the goGet() or doPost() method of this servlet which then uses a bunch of if..else statements to decide what is the code passed from the client side and then decides which function has to be executed. Isn't it?

Glad you could figure it out. :-)

That's correct and it's exactly like this I have resolved the problem, it's a little bit long because I have a lot of if statements but it works so it's okay


ciao tutti


ovidiu

It seems like you failed to frame your question properly in your first post, since what I mentioned is exactly how things are normally done using servlets. As you can see, you are not _directly_ invoking the private function of the Java class but requesting the servlet to execute the method which you want. There is a big difference you know.

I know this kind of thing but it's a little bit ennoying to always pass the name of your functions to your servlet and not to be able to communicate directly with the class instances methods you want.

Also, I have found another way to do the same kind of thing, it's a tool called J2J(Javascript to jsp->http://www.servletsuite.com/servlets/j2j.htm) which does exactly what I want but I couldn't make it work.

Now it doesn't matter any more, all works perfectly with the usual method but it's a heavy way to make things work.

ciao


ovidiu

idiotic and highly dangerous to have anything in place that can bypass the normal request/response system and call any method it wants directly.

Security leaks guaranteed, such a thing is a major billboard with all flashing light for crackers, giving them complete root access to your machine at their leasure.

You know duckman it is not this dangerous to call server methods from a client. Look at Corba and you'll have perfect secure language where client calls server methods. You have a local representation of the object situated on the server on the client and the client communicates with the server using the ORB. It is adapted for Java, C, C++,.... modules.

If the C can communicate with a Java program using Corba why not Javascript? For the moment I'm using the classic method to call my methods but I think that building a system allowing a secure communication between Javascript and other languages using Corba concepts would be a very interesting project.

If you want more details just look on the Internet, you'll find all you want.


ciao


ovidiu

This question has already been answered. Start a new discussion instead.