aspose file tools*
The moose likes Servlets and the fly likes upload.parseRequest(request); giving null. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "upload.parseRequest(request); giving null." Watch "upload.parseRequest(request); giving null." New topic
Author

upload.parseRequest(request); giving null.

Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

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

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

List items;

try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {

System.out.println("File upload exception" +e);
}
Iterator itr = items.iterator();
FileItem itm1 = null;



........ this is my code snippet , i m facing problem on line " items = upload.parseRequest(request);"
it gives null for items..
..Please solve my problem
Davie Lin
Ranch Hand

Joined: Aug 05, 2007
Posts: 294
How do you verify that your request processes is an RFC 1867 compliant multipart/form-data stream?
and how was request first initiated in the file? I think more info is needed for anyone to pinpoint the issue
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
Davie Lin wrote:How do you verify that your request processes is an RFC 1867 compliant multipart/form-data stream?
and how was request first initiated in the file? I think more info is needed for anyone to pinpoint the issue




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
Davie Lin
Ranch Hand

Joined: Aug 05, 2007
Posts: 294
hmm..., seems right to me, I assume that the servlet name is uploadtest and it is map correctly in web.xml?

so what happen when you submit the form, the request is null? or is there error message? This might be out of my league
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
Davie Lin wrote:hmm..., seems right to me, I assume that the servlet name is uploadtest and it is map correctly in web.xml?

so what happen when you submit the form, the request is null? or is there error message? This might be out of my league


In web.xml i m code like this

..........
.......
<servlet-mapping>
<servlet-name>UpLoadTest</servlet-name>
<url-pattern>/uploadtest</url-pattern>
</servlet-mapping>
.........
..........

& my servlet file name is UpLoadTest

I don't know why i m getting prob.
Pl. help me.
 
jQuery in Action, 2nd edition
 
subject: upload.parseRequest(request); giving null.