当前位置: 首页 > news >正文

a做爰视频免费观费网站网站建设万首先金手指13

a做爰视频免费观费网站,网站建设万首先金手指13,上海网络推广外包公司,wordpress升级php7这篇文章描述了在Spring MVC 3中执行错误处理的不同技术。该代码在GitHub上的Spring-MVC-Error-Handling目录中可用。 它基于带有注释的Spring MVC示例。 在Spring 3之前处理异常 在Spring 3之前#xff0c;使用HandlerExceptionResolvers处理异常。 此接口定义一个方法使用HandlerExceptionResolvers处理异常。 此接口定义一个方法 ModelAndView resolveException(HttpServletRequest request,HttpServletResponse response,Object handler,Exception ex) 注意它返回一个ModelAndView对象。 因此遇到错误意味着将被转发到特殊页面。 但是此方法不适用于REST Ajax对JSON的调用例如。 在这种情况下我们不想返回页面我们可能想返回特定的HTTP状态代码。 提供了进一步描述的解决方案。 为了本示例的缘故已经创建了两个假的CustomizedException1和CustomizedException2异常。 要将自定义的异常映射到视图可以并且仍然可以使用impleMappingExceptionResolver SimpleMappingExceptionResolver getSimpleMappingExceptionResolver() {SimpleMappingExceptionResolver result new SimpleMappingExceptionResolver();// Setting customized exception mappingsProperties p new Properties();p.put(CustomizedException1.class.getName(), Errors/Exception1);result.setExceptionMappings(p);// Unmapped exceptions will be directed thereresult.setDefaultErrorView(Errors/Default);// Setting a default HTTP status coderesult.setDefaultStatusCode(HttpStatus.BAD_REQUEST.value());return result;} 我们将CustomizedException1映射到Errors / Exception1 JSP页面视图。 我们还为未映射的异常设置了默认错误视图在此示例中为CustomizedException2。 我们还设置了默认的HTTP状态代码。 这是Exception1 JSP页面默认页面与此类似 %page contentTypetext/html pageEncodingUTF-8% % taglib prefixc urihttp://java.sun.com/jsp/jstl/core % !doctype html html langen headmeta http-equivContent-Type contenttext/html; charsetUTF-8titleWelcome To Exception I !!!/title /head bodyh1Welcome To Exception I !!!/h1Exception special message:${exception.specialMsg}a hrefc:url value//Home/a /body /html 我们还创建了一个虚拟错误控制器来帮助触发这些异常 Controller public class TriggeringErrorsController {RequestMapping(value /throwCustomizedException1)public ModelAndView throwCustomizedException1(HttpServletRequest request,HttpServletResponse response)throws CustomizedException1 {throw new CustomizedException1(Houston, we have a problem!);}RequestMapping(value /throwCustomizedException2)public ModelAndView throwCustomizedException2(HttpServletRequest request,HttpServletResponse response)throws CustomizedException2 {throw new CustomizedException2(Something happened on the way to heaven!);}...} 在Spring 3之前将在Web.xml中将SimpleMappingExceptionResolver声明为Bean。 但是我们将使用HandlerExceptionResolverComposite稍后将对其进行描述。 我们还在web.xml中为HTTP状态代码配置目标页面这是处理问题的另一种方法 error-pageerror-code404/error-codelocation/WEB-INF/pages/Errors/My404.jsp/location /error-page 从Spring 3.X开始有什么新功能 ResponseStatus批注是在调用方法时设置Http状态代码的新方法。 这些由ResponseStatusExceptionResolver处理。 ExceptionHandler注释有助于在Spring中处理异常。 此类注释由AnnotationMethodHandlerExceptionResolver处理。 下面说明了如何在触发我们的自定义异常时使用这些注释将HTTP状态代码设置为响应。 该消息在响应的正文中返回 Controller public class TriggeringErrorsController {...ExceptionHandler(Customized4ExceptionHandler.class)ResponseStatus(valueHttpStatus.BAD_REQUEST)ResponseBodypublic String handleCustomized4Exception(Customized4ExceptionHandler ex) {return ex.getSpecialMsg();}RequestMapping(value /throwCustomized4ExceptionHandler)public ModelAndView throwCustomized4ExceptionHandler(HttpServletRequest request,HttpServletResponse response)throws Customized4ExceptionHandler {throw new Customized4ExceptionHandler(S.O.S !!!!);}} 在用户端如果使用Ajax调用则可以使用以下方法我们正在使用JQuery来检索错误 $.ajax({type: GET,url: prefix /throwCustomized4ExceptionHandler,async: true,success: function(result) {alert(Unexpected success !!!);},error: function(jqXHR, textStatus, errorThrown) {alert(jqXHR.status jqXHR.responseText);} }); 一些使用Ajax的人喜欢返回带有错误代码的JSON和一些用于处理异常的消息。 我觉得这太过分了。 一个简单的错误号和一条消息使其保持简单。 由于我们使用了多个解析器因此我们需要一个复合解析器如前所述 Configuration public class ErrorHandling {...BeanHandlerExceptionResolverComposite getHandlerExceptionResolverComposite() {HandlerExceptionResolverComposite result new HandlerExceptionResolverComposite();ListHandlerExceptionResolver l new ArrayListHandlerExceptionResolver();l.add(new AnnotationMethodHandlerExceptionResolver());l.add(new ResponseStatusExceptionResolver());l.add(getSimpleMappingExceptionResolver());l.add(new DefaultHandlerExceptionResolver());result.setExceptionResolvers(l);return result;} DefaultHandlerExceptionResolver解析标准的Spring异常并将其转换为相应的HTTP状态代码。 运行示例 编译后可以使用mvn tomcatrun运行该示例。 然后浏览 http// localhost8585 / spring-mvc-error-handling / 主页将如下所示 如果单击“例外1”链接将显示以下页面 如果单击“例外2”链接将显示以下页面 如果单击“异常处理程序”按钮将显示一个弹出窗口 这些技术足以涵盖Spring中的错误处理。 更多春天相关的帖子在这里 。 参考 技术说明博客上来自JCG合作伙伴 Jerome Versrynge的Spring MVC错误处理 。 翻译自: https://www.javacodegeeks.com/2012/11/spring-mvc-error-handling-example.html
http://www.zqtcl.cn/news/205820/

相关文章:

  • 沧州地区阿里巴巴做网站修改wordpress标题图片
  • 怎么判断网站开发语言互联网推广模式
  • 做电影网站被找版权问题怎么处理网站做的简单是什么意思
  • 九江网站建设网站制作深圳seo优化服务商
  • 上海网站推广珈维做映射后 内网无法通过域名访问网站
  • 太原网站关键词优化常州企业网站建设公司
  • 网站开发流程详细步骤不用淘宝客api如何做网站
  • xuzhou网站制作wordpress漫画小说
  • 公司建设网站的通知书百度经验官网入口
  • 如何做产品网站的推广静态网页制作总结
  • 网站建设有哪些知识点wordpress 静态
  • 买完阿里云域名如何做网站优化软件排行榜
  • 三五互联网站建设怎么样公司网上推广平台
  • 做网站网页的公司机械网站建设公司推荐
  • 影楼网站制作网站集群建设申请
  • 国内免费的短视频素材网站自己做网站的方法
  • jsp网站建设代码电子印章在线制作生成器免费
  • 叫别人做网站后怎么更改密码一手楼房可以做哪个网站
  • 网站上的图分辨率做多少网站栏目建设存在的问题
  • 山东省建设部网站官网php 开发手机网站建设
  • 新建的网站怎么做seo优化国内最新新闻事件今天
  • ss永久免费服务器河南网站建设优化技术
  • wordpress首页源码深圳seo关键词优化外包公司
  • 网站备案换公司吗网站开发 东莞
  • 济南网站营销彩票网站建设 极云
  • 园区门户网站建设方案著名网站用什么语言做后台
  • 有经验的邵阳网站建设四川省城乡建设网查询
  • 网站打不开怎么做天猫店购买交易平台
  • 什么专业是做网站做网站设分辨率
  • 供水开发建设公司网站建筑案例网站有哪些