File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How do I get my JSP to call a servlets doPost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do I get my JSP to call a servlets doPost " Watch "How do I get my JSP to call a servlets doPost " New topic

How do I get my JSP to call a servlets doPost

Martin Lawrence

Joined: Oct 20, 2000
Posts: 14
Hi All,
how do I get the following jsp code to call the doPost method
on my servlet. Every time I call the servlet it call's it's
doGet method. From what I understand the doGet method has a limit
to the number of bytes it can receive. Since the data that I will
be sending is large I would like to call the servlets doPost method.
<%@page import="*";%>
//Main fields passed to servlet
String apiKey ="doSomeThing";
String xmlString ="This contains a large amount of data";
My Attempt To call the doPost method on servlet ClientToEJB,
instead it calls doGet
<BODY bgcolor="white">
<small><a href='/ClientToEJB?APIKEY=<%=apiKey%>&XMLKEY=<%=xmlString%>'>Click To Send Data To Servlet</a></small>
Ranch Hand

Joined: Nov 30, 2000
Posts: 30
Set the method=POST in the form tag and submit the page to the Servlet you have in the JavaScript after doing all the validations...

srivatsan srinivasan

Joined: Jun 08, 2001
Posts: 26
you r passing values in the query string,so the dogetmethod is called by default.inside the doGet method call doPost(req,res)
which will call the dopost method.
Marya Doery

Joined: Dec 27, 2000
Posts: 15
Just to expand a bit on your question:
The page you sent shouldn't work at all. The <FORM> tag *requires* an ACTION parameter, which you haven't specified. So you're not actually submitting to the servlet, you're GETting from it via the HREF tag.
Here's a page about forms from the horse's mouth:
Also this is about form submission:
Whether or not you use javascript, if you're using the POST method, you'll have to use <INPUT> tags to send the form variables that you want passed to the servlet.
I agree. Here's the link:
subject: How do I get my JSP to call a servlets doPost
jQuery in Action, 3rd edition