4

My problem is, I have a jsp page(say one.jsp) which contains fields(eg: name, city etc) and after I hit on submit button, a new jsp(two.jsp) is opened in a new tab it contains a radio button 'I accept'. when the user now clicks on this radio button, the business logic should get executed. But the problem is the form values of one.jsp(values of name, city etc) are lost.

opening of the new jsp page using window.open is not a new request to the server. I wonder why the form values are lost.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • post source code for one.jsp and two.jsp – anshulkatta May 29 '13 at 11:40
  • 1
    What makes you think opening a new JSP in a new tab isn't a new request?! – Dave Newton May 29 '13 at 13:03
  • Hi Dave, I am opening a new jsp file which belongs to the same project(window.open("jsp path"). I think the browser does not again send a http request to the server. Please correct me if i am wrong. Also, provide a solution for this without using sessions. Thanks! – user1878804 May 30 '13 at 10:36

2 Answers2

1

Since you are using Struts 1 ,Please make sure you declare the fields whose values are to be retained in the ActionForm of the "I Accept" action and do set the values as Form2.setName(Form1.getName());

Or You have to maintain these values as hidden fields in two.jsp.

I guess the above two points would help you !

ashwinsakthi
  • 1,856
  • 4
  • 27
  • 56
  • Hi Ashwin, Can you explain in detail by giving an example taking a single field of one.jsp – user1878804 May 29 '13 at 11:53
  • and also can you explain how to maintain these values as hidden fields in two.jsp with an example. P.S. thx for the response – user1878804 May 29 '13 at 11:56
  • You Will have a field "name" in FormBean1.Create the same field in Formbean2.In your "I Accept" action do set the values as Form2.setName(Form1.getName());. – ashwinsakthi May 29 '13 at 11:59
  • For hidden field you can use the example given here http://www.mkyong.com/struts/struts-htmlhidden-hidden-value-example/ – ashwinsakthi May 29 '13 at 12:02
  • Hi Ashwin, I have created a new form(form2 having the same fields as form1). I have written setters and getters for form2. In that I used Form2.setName(Form1.getName()) after creating object of form1 in form2. Is that what you mean? I still get null values after I do this. Please help. Thx for your support! – user1878804 May 29 '13 at 12:30
  • Please go thru a struts tutorial...I guess you have missed some mapping in struts-config.xml – ashwinsakthi May 29 '13 at 13:21
  • but u meant what I thought u said, right? I have given form2 in the mapping for the action. – user1878804 May 29 '13 at 13:31
  • please let me know of any additional things that need to be done in struts-config.xml I replaced form1 with form2 in the mapping. Thanks! – user1878804 May 29 '13 at 13:35
  • correction to the above comment. I wrote in formbean tag- newly created form2 and in action tag mapped with action class for this form2. Form1 is already in tag – user1878804 May 29 '13 at 13:48
1

You are going from from one jsp to another jsp.But form values processed from one jsp to another jsp only>but you are expecting that values to submit form.

So you can do one thing you have get that values using request.getParameter();

and then you have to set that values to which you need.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Suresh U
  • 463
  • 3
  • 14