Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doing a POST and req.getParameter - No data ?

 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic