spring mvc 对异常的处理

 时间:2026-02-16 04:39:50

1、在控制器添加异常处理

@Exception'Handle(异常类名)

public String handle(类名){

   return  “异常的页面”;

}

发生指定异常时跳转

spring mvc 对异常的处理

2、这种异常处理方式并不能处理404请求错误,需要在web.xml配置错误页面

<error-page>    <exception-type>java.lang.Throwable</exception-type>    <location>/WEB-INF/views/error/404.jsp</location>  </error-page>

spring mvc 对异常的处理

3、/**

* 向所有的用户发送消息

* @param message

*/

public static void sendMessage(String message){

Set<WebSocket> keySet = userconnections.keySet();

synchronized (keySet) {

for (WebSocket conn : keySet) {

String user = userconnections.get(conn);

if(user != null){

conn.send(message);

}

}

}

}

spring mvc 对异常的处理

4、@RequestMapping(value="/delete",method=RequestMethod.GET,produces="text/html;charset=UTF-8")

public String delete(RedirectAttributes ra,String id,HttpServletRequest request){

spring mvc 对异常的处理

5、HttpSession session = request.getSession();

PageData d = (PageData) session.getAttribute("dealer");

//单个,集合删除,查询后条件不丢失删除

dealerService.deleteAll(StringUtils.StringToList(id));

spring mvc 对异常的处理

6、return "redirect:1/dealerList?jyxkz="+StringUtils.nullTo(d.get("jyxkz"))+"&name="+StringUtils.nullTo(d.get("name"))

spring mvc 对异常的处理

7、+"&storeName="+StringUtils.nullTo(d.get("storeName"))+"&phone="+StringUtils.nullTo(d.get("phone"));

}

spring mvc 对异常的处理

  • spring mvc的转发和异常处理
  • SpringMvc怎么处理返回值
  • SpringMVC模式
  • Spring MVC安全访问
  • springMVC基础配置
  • 热门搜索
    余姚旅游 旧金山旅游 普洱旅游 烟台旅游景点大全 梅州旅游景点大全 东北旅游景点 凤阳旅游 旅游介绍 衡山旅游 日本旅游线路