Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes calling doGet(), doPost() on html page load Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling doGet(), doPost() on html page load" Watch "calling doGet(), doPost() on html page load" New topic
Author

calling doGet(), doPost() on html page load

seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
Hi,
I have a html page which has one submit type button. on clicking this button, a request is sent to server side to invoke doGet(), doPost() methods. Here, How to eliminate or bypass the button click process. i.e. on completing the html page load, automatically the button click event should fire (instead of clicking on the button manually). I want to bye pass this html page and want to call the servlet directly.

please suggest/help

bye for now


Seetharaman Jayaraman
Only Change is Changeless
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Well if you need to submit a form on page load, you can use this simple trick



You can also use this code



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41120
    
  45
Why is the web app serving a page that the user is not supposed to see or interact with in the first place? Instead of going through the response->request->response cycle, wouldn't it be easier to do whatever should happen in the first response?


Ping & DNS - my free Android networking tools app
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Use javascript.

Here is a really bad way to do it.



On first thought why do you want to do something like this? Why create a page having just a single button?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
Hi all,
The below script solves the problem

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Terrible. Highly terrible. This is simply a very bad practice. You shouldn't even think about it.

Just let the url-pattern of the servlet cover the request url. Then its doGet() will be called. That's all.
 
jQuery in Action, 2nd edition
 
subject: calling doGet(), doPost() on html page load
 
Similar Threads
how to load an image in a jsp
ReverseServlet.java
Doubts in HTTP Methods behaviour
Advantage of doGet method ?
servlet