【发布时间】:2012-05-09 21:02:54
【问题描述】:
我制作 html 页面来上传带有描述形式的文本框的图像。 我使用了 multipart/form-data ;在servlet的dopost中,我使用 ServletFileUpload 上传 = 新的 ServletFileUpload();
为了获取字符串参数,我使用了 request.getparameter(); 但它总是给我NULL ??? 我怎样才能得到它??
html ::
<form name="filesForm" action="/upload" method="post" enctype="multipart/form-data">
File : <input type="file" name="file">
<textarea name = "description"
rows = "4" cols = "30">Enter comments here.</textarea>
<input type="submit" name="Submit" value="Upload File">
在小服务程序上:
ServletFileUpload upload = new ServletFileUpload();
upload.setSizeMax(500000000);
FileItemIterator iterator = null;
try {
iterator = upload.getItemIterator(req);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // to handle contents or
// instances of request.
FileItemStream item = null;
try {
item = iterator.next();
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // get access each item on iterator.
java.io.InputStream in = item.openStream(); // allows to read the items contents.
Blob imageBlob = new Blob(IOUtils.toByteArray(in)); // store each item on Blob
// object after converting them to Bytes.
/*……….
Note: we are concerned on uploading images files. So the type of files is either (.jpg or gif)
……….
*/
PersistenceManager pm = PMF.get().getPersistenceManager();
String counter="1";
ServletOutputStream outt = resp.getOutputStream();
//match incoming request Content type and invoke appropriate method for handel request
【问题讨论】:
标签: html google-app-engine servlets file-upload servlet-filters