aspose file tools*
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
Author

Doing a POST and req.getParameter - No data ?

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Doing a POST and req.getParameter - No data ?
     
    Similar Threads
    help needed with jsp:getProperty
    RequestDispatcher issue
    A page not found error
    servlet dispatcher not works
    form validation