我的catalina.out中没有异常消息(No Exception message in my catalina.out)

编程入门 行业动态 更新时间:2024-10-28 04:24:58
我的catalina.out中没有异常消息(No Exception message in my catalina.out)

我正在使用spring控制器从表中获取值。

如果某些id的表中没有数据,我在catalina.out文件中无法获得任何异常。 我正在生成一个WAR并放在tomcat7的webapps文件夹中。

我想在没有id的数据时显示错误页面。 现在它进入了默认错误页面。 我需要显示其他错误页面,其中显示“此Id没有记录”。

任何人都可以暗示一下这个吗?

这是班级,

@Controller public class GenerateController extends AbstractController { @Resource private UserService userService; @Resource private LoanService loanService; @Resource private GroupService groupService; protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String groupID = request.getParameter("groupId"); Integer conv = Integer.valueOf(Integer.parseInt(groupID)); Group group = this.loanService.getGroupById(conv.intValue()); GroupLoan groupLoan = this.groupService.getGroupLoanByLoanId( ((Loan)group.getLoans().get(0)).getId().longValue()); LoanDTO loan = this.loanService.getLoanById(groupLoan.getLoanId().longValue()); GroupDTO groupDto = this.groupService.getGroupById(loan.getGroupLoan().getGroupId().longValue()); ModelAndView modelAndView = new ModelAndView(); return modelAndView; } }

I am using spring controller to get the values from tables.

If data is not there in table for some id's, I couldn't get any exception in catalina.out file. I am generating a WAR and placed in webapps folder of tomcat7.

I would like to show an error page while getting no datas for id's. Now it went to default error page. I need to show other error page which says "There is no record for this Id" for this.

Can anyone give a hint in this?

Here is class,

@Controller public class GenerateController extends AbstractController { @Resource private UserService userService; @Resource private LoanService loanService; @Resource private GroupService groupService; protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String groupID = request.getParameter("groupId"); Integer conv = Integer.valueOf(Integer.parseInt(groupID)); Group group = this.loanService.getGroupById(conv.intValue()); GroupLoan groupLoan = this.groupService.getGroupLoanByLoanId( ((Loan)group.getLoans().get(0)).getId().longValue()); LoanDTO loan = this.loanService.getLoanById(groupLoan.getLoanId().longValue()); GroupDTO groupDto = this.groupService.getGroupById(loan.getGroupLoan().getGroupId().longValue()); ModelAndView modelAndView = new ModelAndView(); return modelAndView; } }

最满意答案

你可以通过几种方法实现这一目标,

1.)从Controller本身return a view

String message = "There is no record for this Id" +id; return new ModelAndView("myPage", "message", message);

myPage可以是你的错误页面。

2.)从Controller ,抛出一些自定义异常,比如GroupNotFoundException 。

有关详细说明,请参阅此处。

There are few ways you can achieve this,

1.) From Controller itself, return a view

String message = "There is no record for this Id" +id; return new ModelAndView("myPage", "message", message);

where myPage can be your error page.

2.) From Controller , throw some custom exception, say GroupNotFoundException.

Please refer this for detailed explanation.

更多推荐

本文发布于:2023-08-08 01:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466713.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   消息   catalina   Exception   message

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!