Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParameter() returns a null value in the servlet

 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am struggling with a basic stuff and I could not succeed, I have developed many web apps but never faced a similar problem, please help me out...

My servlet is returning null value for request.getParameter("pname");

JSP Code:


web.xml



Servlet Code



-Nandhakumar S.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nandhakumar Soundarrajan wrote:Expecting your response...

"Expecting"? Don't you think that's a tad rude? You might want to re-evaluate your approach.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not at all clear how the servlet is invoked and what relationship it has to the JSP as the action of your form submits to another JSP, not the servlet.
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, I am new to this forum...

Actually the form submit will be calling



I was trying several things, but even a JSP could not get the parameter from the request

Sorry that's my mistake, please help me out
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nandhakumar Soundarrajan wrote:





your url-pattern is <url-pattern>/newproject</url-pattern> in web.xml
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seetharaman,

I have tried that but not working... for the past two days I am struggling with this, I don't no what went wrong.. other webapps in the same server works fine.
 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well first make sure that the capitalization is correct. I think request parameters are case sensitive so Pname and pname are different. Although your code shows correct capitalization, still it would be a good idea to recheck it.

Also I'm not sure of the input tag syntax you are using. Try using this

 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


HTML tag atrributes should be in double quotes.

Try changing to



Hope it will solve your problem.
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It didn't workout

Also, I tried submitting the form to a JSP file and in the JSP also, I am unable to get the parameter...
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.
Are you sure the request in getting posted to your servlet.

Secondly, have you changed the attributes to double quotes..

Its not only input tag but all the tag attributes available in your form/html.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Inayath wrote:
HTML tag atrributes should be in double quotes.


For information : it is not must

Coming to the problem . did you get any exception ? what you see in your browser response?
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not getting any exception in my console and browser is blank..
 
srinivasa varadhan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can you try printing the parameter names from the request?



 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srini,

request.getParameterNames() also returned null value...
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getParameterNames() never returns null. In case 'request' has no parameters, the method returns an empty Enumeration.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Inayath wrote:Secondly, have you changed the attributes to double quotes.

Eitehr double or single quotes can be used, though it more customary to use double quotes.
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marimuthu,

The getParameterNames returned empty enumerator java.util.Hashtable$EmptyEnumerator@1b044df
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I just found that my doGet is working, but I do not know, why doPost is not working...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nandhakumar Soundarrajan wrote:I just found that my doGet is working, but I do not know, why doPost is not working...

 
jack wenttohill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I know you get it using doGet, but still my curiosity is the URL patern in form action tag, it shouldn't contains a slash /
The code above will work fine for doPost(..)

Thanks
Jack
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please help me out in finding why my doPost is not working...

Sorry to bother you all, its a bit urgent..
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your Servlet Code . earlier you post only doPost() . it might be help to figure out the problem
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP and web.xml will be useful as well.
 
kan nat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

there is no issue in your jsp/servlet, i tried its working , since you are using system.out.println, the servlet prints the form values in standard output, not the browser. if you want it to print in browser , use printwriter instead. let me know if you able to.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic