javascript to jsp

Thread Solved
Reply

Join Date: Jun 2007
Posts: 7
Reputation: ovidiu61 is an unknown quantity at this point 
Solved Threads: 0
ovidiu61's Avatar
ovidiu61 ovidiu61 is offline Offline
Newbie Poster

javascript to jsp

 
0
  #1
Jun 18th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: javascript to jsp

 
0
  #2
Jun 18th, 2007
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).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 7
Reputation: ovidiu61 is an unknown quantity at this point 
Solved Threads: 0
ovidiu61's Avatar
ovidiu61 ovidiu61 is offline Offline
Newbie Poster

Re: javascript to jsp

 
0
  #3
Jun 19th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: javascript to jsp

 
0
  #4
Jun 20th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: javascript to jsp

 
0
  #5
Jun 21st, 2007
> 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 don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 7
Reputation: ovidiu61 is an unknown quantity at this point 
Solved Threads: 0
ovidiu61's Avatar
ovidiu61 ovidiu61 is offline Offline
Newbie Poster

Re: javascript to jsp

 
1
  #6
Jun 22nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: javascript to jsp

 
0
  #7
Jun 22nd, 2007
> 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 don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 7
Reputation: ovidiu61 is an unknown quantity at this point 
Solved Threads: 0
ovidiu61's Avatar
ovidiu61 ovidiu61 is offline Offline
Newbie Poster

Re: javascript to jsp

 
0
  #8
Jun 22nd, 2007
Originally Posted by ~s.o.s~ View Post
> 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: javascript to jsp

 
0
  #9
Jun 22nd, 2007
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 don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 7
Reputation: ovidiu61 is an unknown quantity at this point 
Solved Threads: 0
ovidiu61's Avatar
ovidiu61 ovidiu61 is offline Offline
Newbie Poster

Re: javascript to jsp

 
0
  #10
Jun 22nd, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC