简体   繁体   English

异常 org.apache.jasper.JasperException:java.lang.NullPointerException 根本原因 java.langullException.N

[英]exception org.apache.jasper.JasperException: java.lang.NullPointerException root cause java.lang.NullPointerException

Everytime I run this jsp I get the following error exception:每次我运行这个 jsp 时,我都会收到以下错误异常:

org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.JasperException:java.lang.NullPointerException

root cause根本原因
java.lang.NullPointerException java.lang.NullPointerException

Here is my code:这是我的代码:

<%@page import="Business.Account"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
   <head>
      <title>Account Summary Page CHATTA</title>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <style>
         body {background-color: powderblue;}
         h1   {color: blue;}
         p    {color: red;}
         div {text-align-center;}
      </style>
   </head>

       <% 
           Account a1 = (Account)session.getAttribute("a1");
           %>
      <h1 align="center"> CHATTABANK SUMMARY</h1>
      <br>
      </br>
      <form>
         <div>
            <label for="AcctNo">Accnt ID:</label>
            <input type="text" name ="AccntNo" value="<%=a1.getAcctNo()%>"/></br>
            <label for="CustID">Cust ID:</label>
            <input type="text" name="CUSTID" value="<%=a1.getCid()%>"/></br>
            <label for="Type">Type: </label>
            <input type="text" name="Type" value="<%=a1.getType()%>"/></br>
            <label for="Balance">Balance:</label>
            <input type="text" name="Balance" value="<%=a1.getBalance()%>"/></br>
         </div>
         <div>
         <input type="submit" name="subBtn" value="lookup"/>

         <input type="reset" name="rstBtn" value="clear"/>
      </form>

</html>

Let me know, if any more code is required.如果需要更多代码,请告诉我。

You should handle the case where the session does not contain the attribute "a1" to avoid potential NullPointerExceptions calling methods on a null Account reference.您应该处理 session 不包含属性“a1”的情况,以避免潜在的 NullPointerExceptions 调用 null 帐户引用上的方法。 After you retrieve the "a1" attribute, you should also check that the object is actually a Business.Account object to prevent class cast related exceptions.检索“a1”属性后,还应检查 object 实际上是 Business.Account object 以防止与 class 转换相关的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM