• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling servlet from a Javascript

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me in calling a servlet from a javascript? I am new to this. Please help. Thanks in Advance.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You can use following in script
document.formName.action="/servletName";
document.formName.submit();
Regard,
Gajanan
 
P Agarwal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply. But actually I want to call the servlet which would return me one XML, that is to be parsed. So if I submit the form, how will I get the XML? I don't have any idea as how to retrieve XML from servlet called through Javascript.
If you can give me any clue...
Regards,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript (which runs clientside in this context) cannot directly call a servlet - since it is serverside code. What it can do (as Gajanan C explains) is make an HTTP request to the server. What will come back is probably another HTML page. If you then want to run clientside JavaScript with variables dynamically set in the servlet you will have to render them into the HTML page. For example:
[code]
<script language="JavaScript">
alert("I'm doing something with XML: " + <%=xmlStringFromJSP%> ) ;
</script>
[ June 03, 2004: Message edited by: Paul Sturrock ]
 
today's feeble attempt to support the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic