DelMobilecardsController  --- 删除操作Contorler
ListMobilecardsController --- 查询操作Contorler
无论 删除是否成功 还是失败,都会跳转到查询 Contorler去。
 
删除操作失败,会抛出异常,如何把异常信息传给ListMobilecardsController?
 
Ctorller 1(删除操作):
 @Controller  
public class DelMobilecardsController  
{  
    private static final Logger logger = LoggerFactory.getLogger(DelMobilecardsController.class);  
  
    @RequestMapping(value = "/delMobilecards.action", method = RequestMethod.POST)  
    public ModelAndView delMobilecardsAction(@RequestParam(value = "id", required = false)  
    Long[] ids)  
    {  
        ModelAndView modelAndView = new ModelAndView("mobilecard/listMobilecards");  
  
        try  
        {  
            MobilecardService mobilecardService = (MobilecardService) BSSBeanFactory  
                    .getBean(MobilecardService.BEAN_NAME);  
            mobilecardService.delMobilecards(ids);  
        }  
        catch (DtuException e)  
        {  
            logger.error(e.getErrorCode(), e);  
  
            BindingResult bindingResult = new BindException(e, "");  
            bindingResult.reject(e.getErrorCode());  
            modelAndView.addObject(bindingResult.getModel());  
        }  
  
        return modelAndView;  
    }  
}  
  
Ctorller 2(查询操作):
 
 @Controller  
public class ListMobilecardsController  
{  
    @RequestMapping(value = "/listMobilecards.action", method = RequestMethod.GET)  
    public ModelAndView listMobilecardsAction(@RequestParam(value = "curPage", required = false)  
    Long curPage)  
    {  
        ModelAndView modelAndView = new ModelAndView("mobilecard/listMobilecards");  
  
        if (null == curPage)  
        {  
            curPage = 1l;  
        }  
  
        Pager pager = new Pager();  
        pager.setCurPage(curPage);  
  
        MobilecardService mobilecardService = (MobilecardService) BSSBeanFactory.getBean(MobilecardService.BEAN_NAME);  
        mobilecardService.findMobilecardsByPager(pager);  
  
        modelAndView.addObject("pager", pager);  
  
        return modelAndView;  
    }  
}  
  

解决方案 »

  1.   

    从一个控制器跳转到另一个控制器,楼主应该使用forward:前缀在mobilecard/listMobilecards(或许应该是/listMobilecards.action)前,否则会奔视图去了。
    异常传递,最简单的做法就是放Model中,当普通对象传吧。
      

  2.   

    简单说就是把 excpetion instance 塞 到 request 里面。 转发到下一个环节。
      

  3.   

    你好,我刚接触spring3 mvc做项目,能发一份能运行的事列给我吗,谢谢!!!!!!!!