`
flashdream8
  • 浏览: 678691 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

upload.parseRequest(request) 结果为null

 
阅读更多

 

原因:

          

原因是你web.xml中,struts2的过滤器,把HttpServletRequest变成了MultiPartRequest,所以
upload.parseRequest(request); 必然是null。

解决方法是,在web.xml中
将/* 改成.action

----------------------------------------

其他做法:

个servlet.Filter,并且把它的filter次序放到struts2的filter次序之前。主要源码如下:

   
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(new StrutsRequestWrapper((HttpServletRequest) request), response);
    }


这里先用StrutsRequestWrapper来给他wrapper一次,这样在经过struts2的filter的时候就不会有问题了。为啥呢?可以自己看看这个类
org.apache.struts2.dispatcher.Dispatcher里面的wrapRequest方法,有这么个判断:

    // don't wrap more than once
    if (request instanceof StrutsRequestWrapper) {
        return request;
    }

可以查看 http://auzll.iteye.com/blog/919981 具体解决方法



分享到:
评论

相关推荐

    使用fileupload组件实现文件上传功能

    List<FileItem> list = upload.parseRequest(request); 每个FileItem对象对应一个表单项,包含了表单项的详细信息,例如字段名、文件名、文件内容、文件类型等。FileItem对象提供了多种方法,例如: * ...

    Volley#Request(GsonRequest,MultiPartRequest)

    MultiPartRequest request = new MultiPartRequest(Request.Method.POST, UPLOAD_URL, YourResponseClass.class, new Response.Listener() {...}, new Response.ErrorListener() {...}); request.addFilePart(...

    fileupload

    items = upload.parseRequest(request); iterator = items.listIterator(); hd = tf.newTransformerHandler(); // Set the XML handler. Transformer serializer = hd.getTransformer(); // You'll serialize ...

    Apache Commons fileUpload实现文件上传

    List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()) { String ...

    ajaxfileupload.js

    if (request.Files == null || request.Files.Count ) throw new ApplicationException("no file to be uploaded!"); var file = request.Files[0]; var filename = System.IO.Path.GetFileName(file.FileName);...

    fileupload上传代码与txt文件取值实例

    List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String fileName = item.getName()...

    FileUploadAndDownLoad

    List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { String fileName = item.getName(); // 保存文件到服务器 item.write(new File(...

    java servlet上传文件

    try { // 获取上传文件的列表 List<FileItem> items = upload.parseRequest(requestContext); Iterator<FileItem> iter = items.iterator(); // 遍历上传的文件,进行处理 while (iter.hasNext()) { FileItem item ...

    Struts上传文件实现代码

    List<FileItem> items = upload.parseRequest(ActionContext.getContext().getServletRequest()); for (FileItem item : items) { if (!item.isFormField()) { file = item.getFile(); fileContentType = item....

    web页面导入csv文件

    fileItem = (FileItem) upload.parseRequest(request).get(0); } catch (Exception e) { // 处理异常 } if (fileItem != null && !fileItem.isFormField()) { String fileName = fileItem.getName(); // ...

    commons.jar

    List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { // 处理文件项 } } ``` 4. 遍历`FileItem`列表,处理每个上传的文件。 ```java String ...

    java实现文件的上传.docx

    List<FileItem> items = upload.parseRequest(req); // 遍历 FileItem 列表 for (FileItem item : items) { // 获取上传的文件内容 InputStream in = item.getInputStream(); // 处理文件内容 // ... } } }...

    jsp组件(网站文件上传以及下载,包括案例)

    List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { String fileName = item.getName(); // 保存文件到服务器路径 File uploadedFile = new ...

    51CTO下载-FileUploadStruts

    List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { String fileName = item.getName(); // 处理文件保存逻辑 item.write(new File("保存路径...

    jsp 简单实现上传下载功能

    items = upload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } for (FileItem item : items) { if (!item.isFormField()) { String fileName = item.getName(); ...

    t2_JAVA系统_

    List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); item.write(new File("指定的...

    commons-fileupload-1.3.2jar包和commons-io-2.5jar包.zip

    items = upload.parseRequest(request); } catch (FileUploadException e) { // 处理异常 } for (FileItem item : items) { if (!item.isFormField()) { String fileName = item.getName(); // 保存或处理...

    jsp实现向oracle中blob字段上传附件

    List<FileItem> items = upload.parseRequest(request); FileItem file = items.get(0); String fileName = file.getName(); byte[] content = file.get().getBytes(); ``` 4. **连接Oracle数据库** 使用JDBC...

    struts框架文件上传

    items = upload.parseRequest(request); } catch (FileUploadException e) { log.error("Failed to parse upload request", e); return mapping.findForward("error"); } for (FileItem item : items) { if ...

    JSP实训六student(JSP实现图片上传和读取显示).doc

    List pictureList = dfu.parseRequest(request); Iterator it = pictureList.iterator(); while (it.hasNext()) { FileItem item = (FileItem) it.next(); String pictureName = item.getName(); ...

Global site tag (gtag.js) - Google Analytics