• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I read form fields in another html or jsp page

 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one html page and in that page there are number of hidden fields. But I don't know howmany fields are coming in the URL. How do I read all those fields in when form is submited.
For ex:
<html>
<body>
<form name="form1" action="test1.jsp">
<input type="hidden" name="price1" value="23.34" >
<input type="hidden" name="qty1" value="2">
<input type="hidden" name="price2" value="33" >
<input type="hidden" name="qty2" value="3">
etc....
..........
<input type="submit" name="click" value="Click Here"
</form>
</body>
</html>

In the above html page I don't know how many values are coming in the URL if user clicks "Click Here" button. How do I read all the fields in test1.jsp page. Please can any one provide some sample code.

Thanks,
Suprita.
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use the "request" to handle that.

Check the Servelt request API to find that you have getParameterNames().

This will give you all the parameter names that came from the form that you submitted. You just cycle thru the enumeration, to get all the values

Hope this helps
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to do this on the server side or client side?

Eric
 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick response..........
 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do I sent current window form fields to new window.
For example I have one jsp page is like:
<script language="JavaScript1.2">
function disp(){
window.open(test1.jsp);
}
</script>
<body>
<form name="form1">
<input type="hidden" name="price1" value="23.34" >
<input type="hidden" name="qty1" value="2">
<input type="hidden" name="price2" value="33" >
<input type="hidden" name="qty2" value="3">
<input type="hidden" name="price3" value="44" >
<input type="hidden" name="qty3" value="4">
<input type="button" name="click" value="ClickHere" >
</form>
</body>

When I click button it is opening new window. But how to I pass all the hidden variables, text fields to new window. I want to display all these values in new window. Any help please..........
 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I use getParameterNames() to read all the parameter names and correspondig values it is displaying parameter from last to first i.e
if you see the above html code the form fields displaying are
price3 = 44
qty = 4
price2 = 22
qty = 3
etc...
I want the reverse way i.e
price1= 11
qty1 = 1
price2 = 22
qty = 2
etc............
What i have to display form fiels from first to last (by default getParameterNames() is getting parameters from last to first).
 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to that on server side. My basic stuff is I have one jsp page and that has lot of hidden fields and different button on this page. There is button some thing like "Export". When I click this button I need to dispaly all the hidden fields information in the new window(basically it is another jsp page). If I use getParameterNames() it should display the parameter names in from last to first (from URL). i.e
let say url = "http://.../test.jsp?price1=12&qty1=1&price2=23&qty=2....."
Then getParameterNames() get values like
price3= 324
qty3= 5
price2 = 23
qty2= 2
price1= 12
qty1 = 1
etc..........
I want some thing like
price1 = 12
qty1= 1
price2= 23
qty2 = 2
etc..........

Thanks.
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think the API's can help you with that..
What I would suggest is that you have some logic by which you construct these names.. Maybe in form one, have some indicator ( read hidden field) ,which will contain the total number of fields.. for example u have price1 to price5, pass the value 5 as a hidden form.

then in the bean, iterate to find out the values.

you can do a
for(int incr =1; myCount < hiddenFieldValue; incr ++)
if(null != request.getParameter("price"+incr))
PRINT request.getParameter("price"+incr)

hth
 
suprita konda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. The way you told make sence to me..........................
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic