Win a copy of Emmy in the Key of Code this week in the General Computing forum!
    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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

getting nullPointerException on line upload.parseRequest(request);

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
I m using this line in my jsp page...
<form name="uploadtest" action="uploadtest" method="POST" encType="multipart/form-data">


This is my servlet page....

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();


String optionalFileName="";
String fileName="";
boolean fileUpload=false;


boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if(isMultipart)
{
FileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100000);

//List items=null;

try {
List items = upload.parseRequest(request);
System.out.println("Items are"+items);
Iterator itr = items.iterator();
FileItem itm1 = null;

while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();
System.out.println("Entered in Servlet");
if(item.isFormField())
{
String name = item.getFieldName();
System.out.println("Field name: "+name);
if(name.equals("filename"))
optionalFileName = item.getString();

}
else
itm1=item;
}

if (itm1!=null)
{
fileName = itm1.getName();
System.out.println("File name: "+fileName);
}
if (itm1.getSize() > 0)
{

if (optionalFileName.trim().equals(""))
fileName = FilenameUtils.getName(fileName);
else
fileName = optionalFileName;

String dirName = "c:/24-08/";

File saveTo = new File(dirName + fileName);
try {
itm1.write(saveTo);
}catch (Exception e){ }
}
} catch (FileUploadException e) {

System.out.println("File upload exception" +e);
}
}
}
}


......Thanks for replying
Please send me reply .........its very urgent
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Rupa, please Use Code Tags when you post a source code.

Can you please post the stack trace of the exception to make it easier to find the problem...
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator

Ankit Garg wrote:Rupa, please Use Code Tags when you post a source code.

Can you please post the stack trace of the exception to make it easier to find the problem...




Hi,
You asked this only know,
Please solve my problem.
from 2 days i am trying to solve it.
please give response earliest possible.


500 Internal Server Error
java.lang.NullPointerException at authentication.UpLoadTest.doPost(UpLoadTest.java:90) at javax.servlet.http.HttpServlet.service(HttpServlet.java:763) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Rupa,

Please do not create multiple threads for the same discussion. Let's continue this in your other thread here https://coderanch.com/t/459680/Servlets/java/Please-reply-early-upload-parseRequest
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!