aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Calling servlet from JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Calling servlet from JavaScript" Watch "Calling servlet from JavaScript" New topic
Author

Calling servlet from JavaScript

Mam Kat
Greenhorn

Joined: Oct 14, 2005
Posts: 6
Hi,

I have a jsp page. When i click on a button in the page, I want to call servlet class and submit the form in javascript. I can't give form action as servlet class. Can someone help me with this.

thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

You have not clearly stated what your issue is. All you need to do is to set the action of the form to the appropriate URL for the servlet. Is that where you are having difficulty?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sudhir kamath
Greenhorn

Joined: Mar 07, 2002
Posts: 16
Originally posted by Mam Kat:
Hi,

I have a jsp page. When i click on a button in the page, I want to call servlet class and submit the form in javascript. I can't give form action as servlet class. Can someone help me with this.

thanks in advance.


hi,

function bustOut(){
var newWin = window.open("the real url", "subWindow","height=500,width=700,resizable=yes,scrollbars=yes");
}

call this fuction inside a javascript.

HTH,
sundeep kamath
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Why on earth would he want to open a new window?
Mam Kat
Greenhorn

Joined: Oct 14, 2005
Posts: 6
I can't give the form action as URL. I am initially submitting the form on change of a radio button so the form action is given as the same page. (if the selected value of radio button is Yes user is asked to enter one set of values, if it is no another set and these values are used in servlet class)

I want to get the request paramters in the servlet class. So i have to submit the form and invoke the servlet. i am thinking to do this with a button onClick event. How can i do this? is there a better way than what i am thinking?
thanks for the help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Moved to the HTML/Javascript forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

In your onclick handler. set the form action to the URL of the servlet and submit the form.
[ October 25, 2005: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling servlet from JavaScript