Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending data from one servlet to another..

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have ServletA, which has html table output. For each row I have a form element created and at the end of each form I have a submit button. When the user submit, that particular row of data has to be sent to another servlet B. Please Suggest how do I do it?
Thanks
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no answer to your question. Only more questions
WHY oh why are you having servlets generate HTML output? I know this is chapter one of servlets books; how we can do CGI in Java
What Sun suggests for an effective presentation of a Web application, is that you delegate presentation to JSP pages and have Java servlets prep those JSPs with the appropriate beans (objects) that those JSPs will need to render the appropriate UI...
It was called "Model 2" architecture in the "old" servlet days
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not all of us are as deeply in love with JSP as the Sun marketing team. There are huge holes in JSP. Debugging is a huge pain. And it does not solve the issue of separation of HTML from code. A well designed HTML templating scheme is 1000X better than the JSP hack as far as I am concerned.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As to Jairat's question, simply create a form pointing to the servlet you wish to execute.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Jairat, I must ask you again to change your registration to a first and last name format. If you don't, the owners of this web site will revoke your registration.
Please look at this: http://www.javaranch.com/ubb/Forum10/HTML/000180.html
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see a few ways of doing what you require (separate "submit" buttons for each line of a table).
1. Use a separate form for each line of the table. This works well if you don't also need any operations on all the lines at once. You can send the data to the same servlet, but put the row number in a hidden field:

2. Take advantage of the form behaviour with submit buttons. Only the button clicked is sent to the server with the form, all other buttons are ignored, so you can name the button in a unique way:

I'm sure there are other ways, but these two should do for the moment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic