I am getting all parameters of textFields of jsp page.I getting these parameters with Enumeration object that return all parameter names in different order.For example i create textfields in this order id,name,rollNo,Marks.It returns in different order like as rollNo,Marks,id,name.How can I get values in order as i created in jsp page.
faisal hameed wrote:How can I get values in order as i created in jsp page.
I guess you can not. Because the parameters are probably put into a map and map has to deal with collision etc. and has its own order of items. Anyways why you should need that? I can not see any obligation to do what you want.
Exactly as Fatih said that is what happening internally. All the request, session, application scope values are indeed backed up by a HashMap. So you don't have a control on the order of values.
i need it for my Home Assignment.
from first JSP index i have to get my values from text fields when buttn in pushed. But enumeration onject changes the order of all the value which are gotton from txt fields. How can I get the order in which the Values are stored into the enumeration object.
Please Help.
faisal hameed wrote:i need it for my Home Assignment.
from first JSP index i have to get my values from text fields when buttn in pushed. But enumeration onject changes the order of all the value which are gotton from txt fields. How can I get the order in which the Values are stored into the enumeration object.
Please Help.
You can accomplish the same by using the name of each property/parameter. Cant you do that? You can retrieve each parameter by its name and store the value. I don't think you can get an ordered values from the enumeration object until it was backed by it. Even if it so it would be based on the natural order and NOT your order of insertion.
As I said earlier, it is NOT in our hands but the container.
I do NOT know is there a default way. Still if you want to have it done, you can do it manually by prefixing the number (as an order for each component say text field as per your example). Then in the enumeration after retrieving it you can manually get the substring and arrange it in ascending order. -- Overall, it would be a painful job.
Give it a shot if your requirement badly insists you to do so!
faisal hameed wrote:i can get manually all values in order.but if i dont know about no of textfields in jsp page then there is problem.
I believe you have to consider your requirements. How can a servlet/jsp can handle input parameters that are not known until form request processing?
One answer will be : if adding text inputs with javascript is the issue and you have to exactly process the text inputs as in the order that they exist on your jsp page then make text inputs have generic names like "text1", "text2" and so on and pass the number of text inputs to form request handler. But all these are turn around and will bother you some time later when you have to add new functionality to your pages. Or again have them names that reflect the order of the items on your page and consider sorting parameter names. But first one will be an easy and a novice solution.
Regards,
Fatih.
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad: