retrieving values from jsp page

Thread Solved

Join Date: Jul 2008
Posts: 50
Reputation: shijunair is an unknown quantity at this point 
Solved Threads: 0
shijunair shijunair is offline Offline
Junior Poster in Training

retrieving values from jsp page

 
0
  #1
Sep 26th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,275
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 494
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: retrieving values from jsp page

 
-1
  #2
Sep 26th, 2008
Originally Posted by shijunair View Post
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.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: retrieving values from jsp page

 
0
  #3
Sep 26th, 2008
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 :-
  1. <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.
Last edited by stephen84s; Sep 26th, 2008 at 6:06 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 50
Reputation: shijunair is an unknown quantity at this point 
Solved Threads: 0
shijunair shijunair is offline Offline
Junior Poster in Training

Re: retrieving values from jsp page

 
0
  #4
Sep 26th, 2008
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
Last edited by shijunair; Sep 26th, 2008 at 6:19 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: retrieving values from jsp page

 
0
  #5
Sep 26th, 2008
Try checking out request.getParameterValues() method, It should fetch you all the values even if some of the input elements have the same name.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 50
Reputation: shijunair is an unknown quantity at this point 
Solved Threads: 0
shijunair shijunair is offline Offline
Junior Poster in Training

Re: retrieving values from jsp page

 
0
  #6
Sep 26th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 50
Reputation: shijunair is an unknown quantity at this point 
Solved Threads: 0
shijunair shijunair is offline Offline
Junior Poster in Training

Re: retrieving values from jsp page

 
0
  #7
Sep 26th, 2008
Added.......
retrieving values using the code on another jsp page.
thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: retrieving values from jsp page

 
0
  #8
Sep 27th, 2008
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.
Last edited by stephen84s; Sep 27th, 2008 at 2:50 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 50
Reputation: shijunair is an unknown quantity at this point 
Solved Threads: 0
shijunair shijunair is offline Offline
Junior Poster in Training

Re: retrieving values from jsp page

 
0
  #9
Sep 29th, 2008
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='"+approved1 or approved2 or approved3---n times+"' where approver='"+username+"' and m_emp_id='"+id1 or id2 or id3---n ids+"'");
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: retrieving values from jsp page

 
0
  #10
Sep 29th, 2008
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.
Last edited by stephen84s; Sep 29th, 2008 at 6:34 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum


Views: 3404 | Replies: 11
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC