• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

not getting value in doget method of servlet

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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




 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How you will get the value? thats what Mohamed Inayath mentioned earlier
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic