尝试在数据库中查找实体

发布于 2024-11-18 21:21:57 字数 5026 浏览 1 评论 0原文

我有这样的代码:

AJPAController aJPAController;
AClass aClass = aJPAController.find((Integer.parseInt(request.getParameter("id")));

try{
    if(aJpaController.contains(aClass)){
       response.sendRedirect("gosomewhere.com");
     }
}
catch (java.lang.NullPointerException R){
     response.sendRedirect("gosomewhereelse.com");
}

我试图在数据库中查找一个实体,如果该实体在数据库中,那么它将执行一个操作,如果不在数据库中,它将执行另一个操作。

我在尝试先查找然后包含方法时可能会犯逻辑错误..但我不知道。

预先感谢您的帮助。

编辑: 抱歉回复晚了。我必须处理一件紧急的事情。完整的错误堆栈跟踪是:

Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.

Exception Details: java.lang.NullPointerException
  null

Possible Source of Error:
   Class Name: org.apache.jsp.user.report_005fredirect_jsp
   File Name: report_005fredirect_jsp.java from
   Method Name: _jspService
   Line Number: 74

Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.

Stack Trace:

org.apache.jsp.user.report_005fredirect_jsp._jspService(report_005fredirect_jsp.java from :74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lcas.client.filters.SingleSignOutNameAddFilter.doFilter(SingleSignOutNameAddFilter.java:56)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:40)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:50)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:167)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lcas.client.filters.LCASAuthenticationFilter.doFilter(LCASAuthenticationFilter.java:111)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:104)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lrms.web.filter.LocaleFilter.doFilter(LocaleFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:229)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:334)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:814)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:743)
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:936)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:682)
java.lang.Thread.run(Thread.java:619)

I have a code like this:

AJPAController aJPAController;
AClass aClass = aJPAController.find((Integer.parseInt(request.getParameter("id")));

try{
    if(aJpaController.contains(aClass)){
       response.sendRedirect("gosomewhere.com");
     }
}
catch (java.lang.NullPointerException R){
     response.sendRedirect("gosomewhereelse.com");
}

I am trying to find an entity in database, if the entity is in the database then it will perform an action, if it does not it will perform another action.

I might have a logical mistake in trying first find and then contains method.. but I don't know.

Thanks in advance for your help.

EDIT:
Sorry for the late reply. I had to deal with an urgent matter. Full error stack trace is:

Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.

Exception Details: java.lang.NullPointerException
  null

Possible Source of Error:
   Class Name: org.apache.jsp.user.report_005fredirect_jsp
   File Name: report_005fredirect_jsp.java from
   Method Name: _jspService
   Line Number: 74

Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.

Stack Trace:

org.apache.jsp.user.report_005fredirect_jsp._jspService(report_005fredirect_jsp.java from :74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lcas.client.filters.SingleSignOutNameAddFilter.doFilter(SingleSignOutNameAddFilter.java:56)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:40)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:50)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:167)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lcas.client.filters.LCASAuthenticationFilter.doFilter(LCASAuthenticationFilter.java:111)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:104)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
com.labristeknoloji.lrms.web.filter.LocaleFilter.doFilter(LocaleFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:229)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:334)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:814)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:743)
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:936)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:682)
java.lang.Thread.run(Thread.java:619)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十秒萌定你 2024-11-25 21:21:57

只需检查 EntityManager.find(...) 方法。

如果数据库中不存在该实体,它将返回null。因此,这取决于 AJPAController.find(...) 方法的实现,它如何处理该信息。 (只是为了澄清:据我了解,AJPAControllerEntityManager 的包装器。)

Just check the EntityManager.find(...) method.

It will return null if the entity does not exist in database. So it's up to the implementation of the AJPAController.find(...) method what it is doing with that information. (Just for clarification: As I understood, AJPAController is a wrapper around an EntityManager.)

濫情▎り 2024-11-25 21:21:57

您必须向这篇文章“AJPAController”代码添加完整的错误堆栈跟踪。没有这个,我们无法帮助您。
也许 Integer.parseInt 或 request.getParameter 返回 nullpointerException?

You must add to this post "AJPAController" code an full error stacktrace. Without this, we can't help you.
Maybe Integer.parseInt, or request.getParameter return nullpointerexception?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文