我从客户端向servlet发送此请求:
在客户端我正在做: img = Capture.capturePhoto(200,200);
InfiniteProgress inf = new InfiniteProgress();
Dialog progress = inf.showInifiniteBlocking();
MultipartRequest request = new MultipartRequest();
request.setUrl("http://localhost:8080/Test/Test");//calling servlet
request.addData("ImageName.jpg", img, "image/jpeg");
request.addArgument("imgname", "image1");
request.setDisposeOnCompletion(progress);
NetworkManager.getInstance().addToQueue(request);
在服务器端,我正在使用它:
a = req.getParameter("imgname");// but value I'm getting is null
File repository = new File ("F:/SERVLET images");
System.out.println(repository);
DiskFileItemFactory factory = new DiskFileItemFactory(1024, repository);
((DiskFileItemFactory) factory).setRepository(repository);
ServletFileUpload upload = new ServletFileUpload(factory);
try
{
items = upload.parseRequest(req);
}
catch (FileUploadException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext())
{
FileItem item = iter.next();
File f1 = new File ("F:/SERVLET images/pics/'"+a+"'.jpg");
// 'null'.jpg is Printing and image is not displaying
try
{
item.write(f1);
System.out.print(f1);
}
}
我出错了什么?