HI, If I click on a link, it will call a servlets get method. How can I make it call the post method of the servlet. In other words, if i click a href, it should call the doPost method instead doGet method of the servlet. Thanks, Javed.
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
generally, i have seen things like these using the form tags < form ACTION=http://localhost:8080/servlet/FormExample METHOD=POST > The METHOD=POST specifies that the doPost() method of the servlet should be invoked. one other way is that your doGet() method can call doPost(). While this maybe trivial and you may not be looking for this. regds. - satya
Hi, I use doGet() invoke doPost().There are points to be considerred while doing this way. 1)If you are posting sensitive data and do not wish to appear in URl we use post. 2)If the form is very large that you are submitting then also it is advisable to use doPost(). 3)Many times it happens that the browser gives "Method not supported error:doPost()".In this case you invoke doPost() through doGet(). What practice I always follow is doGet() invokes doPost(). This also depends on the requirement.
VAIBHAV <BR>SCJP
Sandeep Jain
Ranch Hand
Joined: Oct 25, 2000
Posts: 124
posted
0
Hi, When u click on the href , the data that is send to the servlet is in the form of get that is the data goes with the url and not with the body u cannot invoke the doPost method with it . However what u can do is in doget u can invoke the doPost mesthod and can carry on with the stuff that u want . But I dont think thats a good idea . As the data is not safe at all in this case. ex: public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doPost(req,res); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { //carry on the stuff u want }
------------------ Sandeep Jain
Try and Try Till u succeed<br /> <br />Sandeep Jain
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
3)Many times it happens that the browser gives "Method not supported error:doPost()". vaibhav: just kinda curious, can you give me one scenario, where you encountered this.....hopefully you can forgive my ignorance as well. Thanks. - satya
Adam Priest
Greenhorn
Joined: Mar 19, 2001
Posts: 5
posted
0
If you want an href to post data to a server, you will probably need create a javascript onclick event to submit a form so when you click on the link, the event will cause a form submit. Of course the form must use the POST method. <A href="myServlet" onClick='document.myForm.submit();'>Post data</A> If you just want the servlet to take the GET but do a POST, it would be something like this: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
Originally posted by triveni sangam: HI, If I click on a link, it will call a servlets get method. How can I make it call the post method of the servlet. In other words, if i click a href, it should call the doPost method instead doGet method of the servlet. Thanks, Javed.
Kevin Mukhar
Ranch Hand
Joined: Nov 28, 2000
Posts: 83
posted
0
Originally posted by Madhav Lakkapragada: [b]3)Many times it happens that the browser gives "Method not supported error:doPost()". vaibhav: just kinda curious, can you give me one scenario, where you encountered this.....hopefully you can forgive my ignorance as well. Thanks. - satya[/B]
This usually happens when the browser tries to POST to a servlet that does not have a doPost() method.
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Oh yeah! I forgot that we don't have to implement both the doGet() and doPost() methods. Thanks Kevin. - satya
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.