aspose file tools*
The moose likes Servlets and the fly likes getting nullPointerException on line upload.parseRequest(request); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

getting nullPointerException on line upload.parseRequest(request);

Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
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

Joined: Aug 03, 2008
Posts: 9313
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
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

Joined: Jan 28, 2008
Posts: 5575

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
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10263
    
168

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


[My Blog] [JavaRanch Journal]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting nullPointerException on line upload.parseRequest(request);