You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sohu <ze...@sohu.com> on 2009/08/13 19:27:34 UTC
About Tapestry HttpServletRequest
I met a problem.
I upload files from a page. In the tranditional servlet, all things are right. The code is :
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DiskFileItemFactory factory = new DiskFileItemFactory();
// set cache
factory.setSizeThreshold(10240000);
// set temp
String base = "d:/upload";
File file = new File(base);
if(!file.exists())
file.mkdirs();
factory.setRepository(file);
ServletFileUpload upload = new ServletFileUpload(factory);
// set the single max
upload.setFileSizeMax(10002400000l);
// set the whole max
upload.setSizeMax(10002400000l);
upload.setHeaderEncoding("UTF-8");
try {
List<?> items = upload.parseRequest(request);
FileItem item = null;
String fileName = null;
for (int i = 0 ;i < items.size(); i++){
item = (FileItem) items.get(i);
fileName = base + File.separator + item.getName();
// save file
if (!item.isFormField() && item.getName().length() > 0) {
item.write(new File(fileName));
}
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
but when I transfer these codes to a setupRender() of a tapestry page. After debug, I found that after it go to "List<?> items = upload.parseRequest(request); ", the varible items will be empty.
I use "HttpServletRequest request = requestGlobal.getHTTPServletRequest();" to get request object, it is not null.
any help?
2009-08-14
Rockie C.
Re: About Tapestry HttpServletRequest
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
You're trying to use a Tapestry page as if it was a servlet. Tapestry
pages are not servlets nor JSP files. Even Tapestry itself is not a
servlet, being a servlet filter.
Use tapestry-upload
(http://tapestry.apache.org/tapestry5.1/tapestry-upload/) to handle file
uploads.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org