Forums Register Login

Doing a POST and req.getParameter - No data ?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
    my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1437 times.
    Similar Threads
    RequestDispatcher issue
    form validation
    help needed with jsp:getProperty
    A page not found error
    servlet dispatcher not works
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 29, 2024 02:02:53.