Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

getting nullPointerException on line upload.parseRequest(request);

 
Rupa Katkar
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
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
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 http://www.coderanch.com/t/459680/Servlets/java/Please-reply-early-upload-parseRequest
 
    Bookmark Topic Watch Topic
  • New Topic