File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Doing a POST and req.getParameter - No data ?  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Doing a POST and req.getParameter - No data ?  " Watch "Doing a POST and req.getParameter - No data ?  " New topic

Doing a POST and req.getParameter - No data ?

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 70

I'm writing a Data Entry Application and I have an HTML form that a user enters 5 fields . I do a "get" to a Servlet that validates the data ( checks database ), if it validates ok, I call another FORM ( JSP ) , This form requires user to enter about 30 fields mostly Textboxes and 3 listboxes. I then do a POST to a Servlet. I want this Servlet to do an Insert to a Table, but when I do a reg.getParameter { i.e. String fname = req.getParameter("firstname"); ] the fname is nulls. I thought req.getParameter would make this data avaliable to the servlet ? Am I missing something here ? I'm new to Servlets & JSP's ( Obviously !) Thanks for help
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

So you have a servlet which receives a request. This servlet checks the request and then forwards to a JSP which generates some HTML. (This is how I translate your description "call another form" into a real description; please correct me if I'm wrong.)

That HTML you just generated contains an HTML form which creates another request, a POST request as it happens, to another servlet.

Now you're asking whether "req.getParameter makes this data available to the servlet". Well, yes, it does, provided that "this data" refers to the data which comes with the request. You have two separate requests here and I suspect you were expecting the second servlet to be getting data which was actually sent to the first servlet.

You'll find it easier to reason about this sort of thing if you concentrate on the requests and responses being sent back and forth. If you think of a JSP as a thing which is "called" then you're likely to misunderstand what is really happening. A JSP is really a thing which sends HTML to the browser.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63854

I always suggest that novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • The first explains how JSP works. The second, how servlets and JSP should be used together in web applications.

    [Asking smart questions] [About Bear] [Books by Bear]
    I agree. Here's the link:
    subject: Doing a POST and req.getParameter - No data ?
    It's not a secret anymore!