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.
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.
> 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. :-)
Last edited by ~s.o.s~; Jun 22nd, 2007 at 11:31 am.
> 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
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.
Last edited by ~s.o.s~; Jun 22nd, 2007 at 12:09 pm.
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.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.