943,937 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 5692
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 18th, 2007
0

javascript to jsp

Expand Post »
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?
Similar Threads
Reputation Points: 32
Solved Threads: 0
Newbie Poster
ovidiu61 is offline Offline
7 posts
since Jun 2007
Jun 18th, 2007
0

Re: javascript to jsp

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jun 19th, 2007
0

Re: javascript to jsp

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.
Reputation Points: 32
Solved Threads: 0
Newbie Poster
ovidiu61 is offline Offline
7 posts
since Jun 2007
Jun 20th, 2007
0

Re: javascript to jsp

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jun 21st, 2007
0

Re: javascript to jsp

> 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jun 22nd, 2007
1

Re: javascript to jsp

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
Reputation Points: 32
Solved Threads: 0
Newbie Poster
ovidiu61 is offline Offline
7 posts
since Jun 2007
Jun 22nd, 2007
0

Re: javascript to jsp

> 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jun 22nd, 2007
0

Re: javascript to jsp

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
> 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
Reputation Points: 32
Solved Threads: 0
Newbie Poster
ovidiu61 is offline Offline
7 posts
since Jun 2007
Jun 22nd, 2007
0

Re: javascript to jsp

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jun 22nd, 2007
0

Re: javascript to jsp

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
Reputation Points: 32
Solved Threads: 0
Newbie Poster
ovidiu61 is offline Offline
7 posts
since Jun 2007

This thread is solved

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.
Message:
Previous Thread in JSP Forum Timeline: Help me about JSP problem...
Next Thread in JSP Forum Timeline: fetching data from the database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC