Handling Multipart request that is not an Action request?

前端 未结 1 750
故里飘歌
故里飘歌 2021-01-16 03:35

I\'ve been thinking if it is possible to handle Multipart request that is not an Action request. There is a reason why it seems impossible to me :

Onl

相关标签:
1条回答
  • 2021-01-16 04:00

    This is the "pattern" that is afaik the best way of handling Multipart requests

    Action request from view layer goes to this method:

    @ActionMapping(params = "javax.portlet.action=sample")
    public void response(MultipartActionRequest request, ActionResponse response) {
        response.setRenderParameter("javax.portlet.action", "success");
        List<MultipartFile> fileList = request.getFiles("file");
    }
    

    render phase follows :

    @RequestMapping(params = "javax.portlet.action=success")
    public ModelAndView process(RenderRequest request, Model model) throws IOException {
        Map map = new HashMap();
        map.put("test", new Integer(1));
        return new ModelAndView("someView", map);
    }
    

    You create a "bean" view :

    @Component("someView")
    public class SomeView extends AbstractView {
        private Logger logger = Logger.getLogger(SomeView.class);
    
        @Override
        protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response)
                throws Exception {
        logger.info("Resolving ajax request view - " + map);
        JSONObject jsonObj = new JSONObject(map);
        logger.info("content Type = " + getContentType());
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(jsonObj.toString());
        response.getWriter().flush();
        }
    }
    

    You add BeanNameViewResolver into your servlet/portlet context:

    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1" />
    
    0 讨论(0)
提交回复
热议问题