I am facing problem while retrieving values from the jsp page.
my database structure is as follows:
-----------------------------------------------------------------------
m_emp_no|from_date|to_date|approver|status|
________________________________________
1002 | 22/9/2008 | 23/9/2008|1003 |pending
1004 | 29/9/2008 | 30/9/2008|1003 |pending
2044 | 15/9/2008 | 16/9/2008|3076 |pending

--------------------------------------------------------------------------
I am retrieving values from database properly using the following sql statement.
the username is stored in session which is the login id of the user.

p=con.prepareStatement("select * from emp_leave_application where approver='"+username+"'");
ResultSet r=p.executeQuery();
while(r.next())
{
String id=r.getString("m_emp_no");

I get two values for the approver 1003 and i am able to display that.I am using <input type="text" name="id" value="<%=id%>" size="4"> but when i want to retrieve these values in a jsp i am using code: String id=request.getParameter("id"); so that i can update the rows in database for the status whether it is approved or cancelled.
But here i am getting only one value using the above code whereas i should get two values if i login with the id 1003.
Please provide a suggestion.
thanks in advance.

Please provide a suggestion.

Use servlets as you should be doing in first place.
Secondly we had discussion on this topic previously and very little changed. You just refuse to listen.

You **have not** pasted the code which is causing the problem or just displaying one record.
Right now I am just shooting in the dark here and assuming the problem lies in this piece of code, if it is inside the while loop :-

<input type="text" name="id" value="<%=id%>" size="4">

It is considered a bad practice to have multiple input elements (except radio buttons, check boxes) to be given the same name or ID.

I was just trying with this code in a jsp because this text box is only to display
<input type="text" name="userid" value="<%=id%> " size="4"> instead of<input type="text" name="id" value="<%=id%>" size="4">

where i get both the values displayed but when i try to retrieve it using
request.getParameter("userid");
I dont get two values for the approver1003.
i have the db connection in servlet also, but even there it comes to the same problem.
please suggest what to do.
thanks

Try checking out request.getParameterValues() method, It should fetch you all the values even if some of the input elements have the same name.

hi stephens,
what i have done now is that i have just modified my code .i have used a counter so that i get specific names for the values.
and i am retrieving it using

Enumeration parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements())
{
String parameterName = (String) parameterNames.nextElement();
String parameterValue = request.getParameter(parameterName);
System.out.println(parameterName+"has values"+parameterValue);
}

suppose i have one text box which gives me name=id1,id2,id3 and a list box which gives me name= ap1,ap2,ap3 ok.Here the above code gives me all the parameter names and values but i just need values for id1,id2,id3 so that using a single parameter and value name i can update the database.Is there any option where i can put an if and else condition such that the name starting with id only should be retrieved and the values for that .
please suggest.
thanks

Added.......
retrieving values using the code on another jsp page.
thanks

Well if the problem was solved then at least mention how it was solved, and mark the thread as solved so other people can use it.
Even previously I have noticed you just do not mention how a certain problem was solved, unless explicitly asked. Its not exactly fun to help such people.

hi stephens,
you are mistaken .the query is not yet solved and i dont know who has marked it as solved.
the very recent coding which i pasted was the coding which i tried it out so that i could get different name such as id1,id2,id3 etc and using enumeration i was retrieving all the values of parameter names.
I might have not framed the question properly because of which it is considered as solved.
Actually i have this code below where i want to update the database for different ids i.e id1,id2,id3 with the status such as approved or cancelled.I dont want to manually update again and again because i dont know when the person is going to apply for leaves.

p=con.prepareStatement("select * from emp_leave_application where approver='"+username+"'");

ResultSet r=p.executeQuery();
while (r.next())
{
if(username!=null)
{
ps=con.prepareStatement("update emp_leave_application set status='"+[B]approved1 or approved2 or approved3---n times[/B]+"' where approver='"+username+"' and m_emp_id='"+[B]id1 or id2 or id3---n ids[/B]+"'");
ps.executeUpdate();
}
}

I want to know what should be written above in the code which is given in bold because the many person apply for leaves and can be 'n' no of times in a year and the approver has to approve the leaves for that id which should be updated in database whether it is cancelled or approved. you can have a look at the database above .Is there any solution for this.
please suggest me.
thanks

Added.......
retrieving values using the code on another jsp page.
thanks

From that anyone will assume the query was solved and one of the moderators might have marked it as solved.

I marked it now as unsolved, due to comment of shijunair.

PS: It could be even you who accidentally mark it s solved. Doesn't matter, now it is again unsolved.

hi peter & stephen,
I have solved my query using iteration.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.