Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I call a servlet from my clientside JavaScript?

Status
Not open for further replies.

Draug

Programmer
Apr 18, 2001
77
CA
Hi,

I have a servlet that does some database accessing. The important thing is that it returns a string.

From my JavaScript on the client, I am trying to call the servlet, and then store the returned string in a variable.

I cant seem to get it to work. Can anyone give me a tip?

Thanks in advance.
 
You're confused. Javascript is on the client (client-side) and servlets happen on the server (server-side).

What you could do is make the servlet into a bean and call it from a jsp page... get the String from the bean and place it in a javascript variable. The javascript variable would look (on the client-side) as if you had typed it in when you made the jsp file.

EXAMPLE:

//Inside the JSP Page...
<jsp:useBean id='mybean' scope='application' class='mypackage.testbean'/>
...

<SCRIPT>
var some_var = &quot;<%= myBean.getString() %>&quot;;
</SCRIPT>

... DO YOU FOLLOW?
I hope this helped! ;-)
- Casey Winans
 
Ya, I follow what you are saying. And, I do know that the servlet is on the server side, and the JS is on the client side.

I do want to call the servlet from my JavaScript. Surely, there must be a way to call something on the server from a client side JavaScript. Are you telling me that there is not?

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top