如何在Spring MVC中静态访问HttpServletResponse

时间:2011-12-07 10:34:56

标签: spring-mvc

如果在控制器中发生异常,我想写一些消息来响应。要做到这一点,我需要响应对象。我可以静态访问当前响应/请求对象,或者我必须将此对象传递给异常,如jsf (FacesContext.getCurrentInstance()getExternalContext()的GetResponse());

 List<View_Probes> getAllProbes(HttpServletResponse response)  throws ResourceNotFoundException{
        try {
          List<Probe>  probes=   inseptraPersistenceService.listAllProbes();

          List<View_Probes> result=  mapper.mapAll(probes, View_Probes.class);

            return result;
        } catch (Exception e) {
             throw  new ResourceNotFoundException(e);

        }
    }


@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {


    public ResourceNotFoundException() {

    }

    public ResourceNotFoundException(Throwable e) {
        super(e);
    }


}

0 个答案:

没有答案