How to forward radio button input from one jsp to another?
Joined: Mar 30, 2005
Sorry if it's a dumb question: I have a jsp page ("A") which has a table, the 1st column is radio buttons, so the user could pick up a row from the table, then click the submit button, so that some more details of that row could be showed in another page, "B".
I specify in struts-submit-congig.xml file that the action associated with page A will be forward to page B. However, when i tried to find out which row has been selected from page A by calling "request.getParameter("id")" in B.jsp, i got "null". In another word, submit of page A doesn't seem to forward the check status of radio buttons to page B.
The name of the input of radio buttons is defined as "id". what else can be missing? It used to work when i put all logic (including constructing the table data) in page A's action class. btw, i have way much more experience in Java than in JSP.
Thank you so much!
Joined: Feb 15, 2005
What you may be missing is that the parameter doesn't automatically get forwarded from JSP A to JSP B without some action on your part in Action A.
Here's the sequence of events:
JSP A is rendered and sent to the browser
The user presses the submit button, thereby sending all form elements as parameters attached to the request object.
If you've defined and coded an ActionForm, Struts automatically populates the ActionForm bean with the values in the parameters.
the Execute() method on Action A is called, and has access to both the parameters and the form bean. It can then take whatever action is necessary based on that information.
Action A forwards to JSP B. If the action does nothing to pass along the information it read, it is lost! In order to pass the information along to JSP B, Action A takes the information from the ID parameter and either places it directly in the request object using the setAttribute() method, or puts it in an ActionForm bean which is then placed in the request object.
JSP B then reads the information from the request, either by using Struts tags that access the ActionForm bean, or by calling the request.getAttribute() method.