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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting nullPointerException on line upload.parseRequest(request);

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Rupa cool. read this
1.http://osdir.com/ml/jakarta.commons.user/2003-07/msg00124.html

2.http://commons.apache.org/fileupload/using.html

3.http://www.java2s.com/Open-Source/Java-Document/Net/apache-common-FileUpload/org.apache.commons.fileupload.servlet.htm

i dont know this references solve your problem or not. but you may get some clue
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic