• Post Reply Bookmark Topic Watch Topic
  • New Topic

URGENT: calling a method in a servlet from the 'action' tag or onclick event

 
Catriona McCann
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a servlet whcih generates a screen in HTML using the out.println(" ") ... technique. In this HTML, I have a sumit button, on the action of that submit I want to call a method (which is within that same servlet) which would pull all information from the screen i.e using request.getParameter(). However I am having problems calling that method ... Is it possible to do this - if so .... how ??
Thanks !!!
Catriona.
 
Mohamed Yousuff
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is very simple problem to solve. Include a hidden tag in the html and set its value to some value. The possible values for this hidden parameter should be two, say x and y. In the servlet say 'serv', in the first line check the value of the hidden parameter. If it is x proceed as normal in the servlet. If it is y then call your function and return. Hope I solved your problem.

Originally posted by Catriona McCann:
Hi,
I have a servlet whcih generates a screen in HTML using the out.println(" ") ... technique. In this HTML, I have a sumit button, on the action of that submit I want to call a method (which is within that same servlet) which would pull all information from the screen i.e using request.getParameter(). However I am having problems calling that method ... Is it possible to do this - if so .... how ??
Thanks !!!
Catriona.


------------------
 
Raghvendra Sharma
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I don't think there is any way to direcly call a method of servlet from within the html code which you are rendering.
The html that it generates is done in run time and that too in the browser's context. onclick etc are meant to be handled in the browser's context by embedded javascript engine.
Yeah, you can reach the same result by pointing to the servlet in your form's action. The submit call will take it over there only.
Don't confuse your generated html with something in the servlet context. It will be active only when the servelt has executed (done) and the user responds to something on the generated html page.
hope it helps
regards
raghav..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!