Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why request.getPaarmeter is returning null?  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , when i run the above code it is throwing me a NullPointerException as request.getParameter("upfile"); is generating null .
Please tell me whats wrong with this ??






Here the name is being null , please tell me why i am not getting name ??

Thanks in advance .
 
Ian Cabigon
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

Looking at your code, this does not seem to throw a NullPointerException.

Have you tried inspecting if the code really does enter the doPost method? Maybe there are prior errors before the code reaches the doPost method.

Could you also check if its just configuration problem in your web.xml or check if your catalina.out has initialization problems.

Hope I can help.

Ian
 
Ian Cabigon
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another question.. I notice you also try to implement the Servlet interface. I think extending HttpServlet class is enough to get it working.

Thanks,
Ian
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

tahnks for the reply , i modified the code as suggested but still

String name = request.getParameter("upfile"); retruns null .

Please suggest why is it so , i am attaching the screen shot to show that the value is returining null .
NULL.jpeg
[Thumbnail for NULL.jpeg]
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the screen it is showing as Ravi Kiranm null, but in the program it is System.out.println("Nameeee"+name); Are you sure, you have posted the correct code for the same..
 
Nivs Solanki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

I am new to this forum

Why request.getPaarmeter is returning null ??

Prasad is right and also do some rectification in html code as follow

<FORM action="MyServlet" method="Post">
to upload: <INPUT TYPE=FILE NAME="upfile"><BR>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>

it will work fine
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad is right and also do some rectification in html code as follow




Before posting the question , i was trying more .

I have taken your HtML code also , but the same thing is happening .



The only good thing is that it is not throwing the NullPointerException when name.getBytes() ; is called (dont know why)

Also see the latest screen shot now :
New.jpeg
[Thumbnail for New.jpeg]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try with

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to (a) use a multipart encoded form, and (b) use a multipart request wrapper and/or file upload library, like Apache Commons FileUpload. Like you did that last time you were talking about uploading files back in May, and a year earlier. In fact, your other question from today was already answered by a question you asked a year ago.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harpreet Singh , your suggestion has solved the problem .

At David

You need to (a) use a multipart encoded form, and (b) use a multipart request wrapper and/or file upload library, like Apache Commons FileUpload.


Is the below really necessary ??

use a multipart request wrapper and/or file upload library, like Apache Commons FileUpload.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For about the 50th time: yes, if you want to upload a file you need to use, and to handle, a multipart request.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if you have access to JavaRanch (and not Google, apparently), you can still search.

http://faq.javaranch.com/java/FileUpload
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!