这是“模式”,是处理多部分请求的最佳方法
来自视图层的 *** 作请求转到此方法:
@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");}
渲染阶段如下:
@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);}
您创建一个“ bean”视图:
@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(); }}
您将BeanNameViewResolver添加到servlet / portlet上下文中:
<bean p:order="1" />
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)