943,833 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 5456
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 26th, 2008
0

retrieving values from jsp page

Expand Post »
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.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
shijunair is offline Offline
50 posts
since Jul 2008
Sep 26th, 2008
-1

Re: retrieving values from jsp page

Click to Expand / Collapse  Quote originally posted by shijunair ...
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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Sep 26th, 2008
0

Re: retrieving values from jsp page

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 :-
html Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Sep 26th, 2008
0

Re: retrieving values from jsp page

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.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
shijunair is offline Offline
50 posts
since Jul 2008
Sep 26th, 2008
0

Re: retrieving values from jsp page

Try checking out request.getParameterValues() method, It should fetch you all the values even if some of the input elements have the same name.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Sep 26th, 2008
0

Re: retrieving values from jsp page

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
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
shijunair is offline Offline
50 posts
since Jul 2008
Sep 26th, 2008
0

Re: retrieving values from jsp page

Added.......
retrieving values using the code on another jsp page.
thanks
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
shijunair is offline Offline
50 posts
since Jul 2008
Sep 27th, 2008
0

Re: retrieving values from jsp page

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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Sep 29th, 2008
0

Re: retrieving values from jsp page

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
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
shijunair is offline Offline
50 posts
since Jul 2008
Sep 29th, 2008
0

Re: retrieving values from jsp page

Quote ...
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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: how to create PDF usng JSP code
Next Thread in JSP Forum Timeline: Form data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC