File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes not getting value in doget method of servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "not getting value in doget method of servlet" Watch "not getting value in doget method of servlet" New topic
Author

not getting value in doget method of servlet

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
i had to delete rows on basic of checkbox
Procedure which i am doing: --
I had a jsp in which on basic of selection of checkbox i am passing empid value to servlet in which do get method is defined which is calling delete () in another java pagewhich is deleting record

jsp page


Servlet is -:


delete method



please suggest what i am doing wrong




Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Nitin,

In your JSP you are populating the values and displaying it.
After that you are trying to get a value from the request object.

Why is the above code in the JSP?

Also in the Delete Servlet you are expecting the value from the below code


Where are you setting the value?

Confusing...! Isn't it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
For starters, having multiple checkboxes all named "Empid" is bound to create problems. Give them distinct names (like Empid1, Empid2, etc.) and see what happens.


Ping & DNS - my free Android networking tools app
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ulf Dittmer wrote:For starters, having multiple checkboxes all named "Empid" is bound to create problems.


I Agree with you completely. unless you need to create dynamic check boxes, for starter better to give separate checkbox name
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Mohamed Inayath wrote:Nitin,

In your JSP you are populating the values and displaying it.
After that you are trying to get a value from the request object.

Why is the above code in the JSP?

Also in the Delete Servlet you are expecting the value from the below code


Where are you setting the value?

Confusing...! Isn't it?


Sorry i had put thewrong code MY code is:

i had to delete rows on basic of checkbox
Procedure which i am doing: --
I had a jsp in which on basic of selection of checkbox i am passing empid value to servlet in which do get method is defined which is calling delete () in another java pagewhich is deleting record

sorry i had put thewrong code MY code is:
JSP is : -




Servlet is :--




delete method code




Object value = request.getAttribute("Empid");
if(value==null) {
System.out.println("Value is null");

I am not getting empid value printed in my servlet .
I am getting Value is null





Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

How you will get the value? thats what Mohamed Inayath mentioned earlier
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
I'm not sure how this code differs -please restrict any code you post to *just the relevant lines*, not close to 200 lines- but you're still creating multiple checkboxes with the same name, and you're still using "getAttribute", when -as Mohamed pointed out- you probably want to use getParameter.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Both codes only differ in this lines in JSP:
String str=request.getParameter("value");
System.out.println(" Str" + str);

which are really irrelevant.

Input fields are not Attributes, are Parameters, so, as the other users have told you use getParameter to get the parameter
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
seetharaman venkatasamy wrote:How you will get the value? thats what Mohamed Inayath mentioned earlier


I am getting the value in servlet by changing it to
Object value = request.getParameterValues("Empid");
System.out.println(value);


But i am not getting value in delete method , i am getting output as "user not deleted,

Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124


When are you setting AttributeUser value and where?

With your code, I believe it will be always give null and the empd id never set/displayed either.

Aren't you getting any NUll pointer exception when you access the page very first time?
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Nitin Belaram wrote:

Object value = request.getParameterValues("Empid");



This code will not compile, you are trying to set to an Object an String[]...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Well, in servlet you are just creating the object


where you are setting the value ? you need to set the value using setter method of User and pass into delete()...get there using getter method of User

Hope this helps
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Albareto McKenzie wrote:
This code will not compile, you are trying to set to an Object an String[]...


ohh... i miss it out . well done Albareto . you need String[] or Object[]
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Thanks man

Anyway, I think that if you just try to make a String value= request.getParameter("Empid"); it should return you something, I don't know exactly what, but something, try that and let us know if something appears in your value var
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Ulf Dittmer wrote:For starters, having multiple checkboxes all named "Empid" is bound to create problems. Give them distinct names (like Empid1, Empid2, etc.) and see what happens.

I'm going to respectfully disagree with this a general notion. It's fine to have multiple checkboxes with the same name, but different values, when they logically represent a group or the same abstraction.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
wood burning stoves
 
subject: not getting value in doget method of servlet
 
Similar Threads
Display output in table
Display table row value in another form
update record for selection of id
Sending checkbox value to two different servlet page
value from servlet to dropdown in jsp