RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1304 | Replies: 11 | Solved
Reply
Join Date: Jul 2008
Posts: 40
Reputation: shijunair is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shijunair shijunair is offline Offline
Light Poster

retrieving values from jsp page

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,704
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 320
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: retrieving values from jsp page

  #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, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Jul 2007
Location: Mumbai(Bombay), India
Posts: 363
Reputation: stephen84s has a spectacular aura about stephen84s has a spectacular aura about 
Rep Power: 3
Solved Threads: 47
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Posting Whiz

Re: retrieving values from jsp page

  #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."
Reply With Quote  
Join Date: Jul 2008
Posts: 40
Reputation: shijunair is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shijunair shijunair is offline Offline
Light Poster

Re: retrieving values from jsp page

  #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  
Join Date: Jul 2007
Location: Mumbai(Bombay), India
Posts: 363
Reputation: stephen84s has a spectacular aura about stephen84s has a spectacular aura about 
Rep Power: 3
Solved Threads: 47
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Posting Whiz

Re: retrieving values from jsp page

  #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."
Reply With Quote  
Join Date: Jul 2008
Posts: 40
Reputation: shijunair is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shijunair shijunair is offline Offline
Light Poster

Re: retrieving values from jsp page

  #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  
Join Date: Jul 2008
Posts: 40
Reputation: shijunair is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shijunair shijunair is offline Offline
Light Poster

Re: retrieving values from jsp page

  #7  
Sep 26th, 2008
Added.......
retrieving values using the code on another jsp page.
thanks
Reply With Quote  
Join Date: Jul 2007
Location: Mumbai(Bombay), India
Posts: 363
Reputation: stephen84s has a spectacular aura about stephen84s has a spectacular aura about 
Rep Power: 3
Solved Threads: 47
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Posting Whiz

Re: retrieving values from jsp page

  #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."
Reply With Quote  
Join Date: Jul 2008
Posts: 40
Reputation: shijunair is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shijunair shijunair is offline Offline
Light Poster

Re: retrieving values from jsp page

  #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  
Join Date: Jul 2007
Location: Mumbai(Bombay), India
Posts: 363
Reputation: stephen84s has a spectacular aura about stephen84s has a spectacular aura about 
Rep Power: 3
Solved Threads: 47
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Posting Whiz

Re: retrieving values from jsp page

  #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."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:49 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC