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

时间:2015-05-14 03:49:45

标签: jsp jdbc nullpointerexception

错误:

输入例外报告

messageInternal Server Error

description服务器遇到内部错误,导致无法完成此请求。

例外

org.apache.jasper.JasperException:java.lang.NullPointerException 根本原因

显示java.lang.NullPointerException note备注GlassFish Server Open Source Edition 4.1日志中提供了异常的完整堆栈跟踪及其根本原因。

EmailConfirmation.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Dentistree</title>
    <link rel="stylesheet" type="text/css" href="EmailConfirmation.css">
</head>
<body>
<button id="home" onmouseover="h1()" onmouseout="h2()"><b>HOME</b></button>
<button id="register" onmouseover="r1()" onmouseout="r2()"><b>REGISTER</b></button>
<button id="login" onmouseover="l1()" onmouseout="l2()"><b>LOGIN</b></button>    
<button id="appointment" onmouseover="a1()" onmouseout="a2()"><b>APPOINTMENT</b></button>
<button id="map" onmouseover="m1()" onmouseout="m2()"><b>MAP</b></button>
<button id="report" onmouseover="re1()" onmouseout="re2()"><b>REPORT</b></button>
<button id="doctor" onmouseover="d1()" onmouseout="d2()"><b>DOCTOR</b></button>

<%@page import="javax.mail.PasswordAuthentication"%>
    <%@page import="java.util.Properties"%>
    <%@page import="javax.mail.Message"%>
    <%@page import="javax.mail.MessagingException"%>
    <%@page import="javax.mail.Session"%>
    <%@page import="javax.mail.Transport"%>
    <%@page import="javax.mail.internet.InternetAddress"%>
    <%@page import="javax.mail.internet.MimeMessage"%>
    <%
            String name = request.getParameter("nmtxt");    
            String pwd = request.getParameter("passtxt");
            String date = request.getParameter("txtdate");
            String address = request.getParameter("txtadd");
            String blood  = request.getParameter("bloodgrp");
            String sex= request.getParameter("sex");
            String email=request.getParameter("emailaddtxt");

        final String username="a@.com";
        final String password="an";
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<5;i++)
        { 
            sb.append((char)(int)(Math.random()*79+23+7));
        }
        String cap=new String(sb);
    Properties props=new Properties();
    props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.starttls.enable", true);
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    String emailtxt1=request.getParameter("emailaddtxt");

    Session ses=Session.getInstance(props,new javax.mail.Authenticator() 
    {
            protected PasswordAuthentication getPasswordAuthentication()
            {
               return new PasswordAuthentication(username, password); 
            }
    });
    try
    {
            Message message=new MimeMessage(ses);
            message.setFrom(new InternetAddress("a@.com"));
            message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailtxt1));
            message.setContent("<body>"+"Hi "+name+".<br>"+"You have signed to dentistree through email id:<b>"+emailtxt1+"</b><br>Your password is:<b>"+pwd+"</b>Thanks for registering to dentistree.Your unique identification number is<b></br>"+cap+"</b></body>","text/html");
            Transport.send(message);
    }
    catch(MessagingException e)
    {
        throw new RuntimeException(e);
    }
    %>  
    <%@ page import ="java.sql.*" %>
    <%
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dentistree","root", "tiger");
            Statement st = con.createStatement();
//ResultSet rs;
            String s="insert into patient(name,password, birthdate, address, gender,email,unique_key,bloodgroup) values ("+"'"+name+"','"+ pwd+ "','" + date + "','" + address + "','" + sex + "','"  + email +"','" + cap + "','" + blood+"')";
            try
            {
                 int i = st.executeUpdate(s);         
            }
            catch(Exception e)
            {
                out.print(e);
            }
            session.setAttribute("mail", email);
   %>    

<div id="maindiv">
    <h1 id="title"><b>DentisTree</b></h1>
     <h3 id="congo" align="center"><b>CONGRATULATIONS!!!</b></h3>
     <form name="mailconfo" action="confirm.jsp">
     <pre id="para">            You've successfully created Dentistree account. You're account activation is just a step away.
        An email has been sent to your email address.It consist of a unique Dentistree key.Enter the key
                                            in the textfield below to activate your account</pre>
     <label id='uniquekey'><b>Enter the unique key:</b></label>
     <input type='text' id='uniquekeytxt' name="uniquekeytxt" required>
    <input type="submit" value="Submit" id="sub">
    <form name="mailconfo" action="confirm.jsp">
 </div>

</body>

Confirm.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Dentistree</title>
    <link rel="stylesheet" type="text/css" href="confirm.css">

</head>
<body>
<button id="home" onmouseover="h1()" onmouseout="h2()"><b>HOME</b></button>
<button id="register" onmouseover="r1()" onmouseout="r2()"><b>REGISTER</b>   </button>
<button id="login" onmouseover="l1()" onmouseout="l2()"><b>LOGIN</b></button>    
<button id="appointment" onmouseover="a1()" onmouseout="a2()"><b>APPOINTMENT</b></button>
<button id="map" onmouseover="m1()" onmouseout="m2()"><b>MAP</b></button>
<button id="report" onmouseover="re1()" onmouseout="re2()"><b>REPORT</b></button>
<button id="doctor" onmouseover="d1()" onmouseout="d2()"><b>DOCTOR</b></button>


<div id="maindiv">
    <h1 id="title"><b>DentisTree</b></h1>
    <%@ page import ="java.sql.*" %>
    <form name="mailconfo">
    <%
        String conf=request.getParameter("uniquekeytxt");   
        String mail=session.getAttribute("mail").toString();

        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dentistree",
        "root", "tiger");
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select unique_key from patient where email='"+mail+"'");
        String s="Update patient set verified='yes' where email='"+mail+"'";
        try{
        if(conf.equals(rs))
        {
            try
            {
                 int i = st.executeUpdate(s);         
            }
            catch(Exception e)
            {
                out.print(e);
            }
            out.print("<h3 align='center'><b>CONGRATULATIONS!!!</b></h1>");
            out.print("<p>Your account has been verified</p>");
            out.print("<p>Click on the login to login to your account</p>");
        }
        else
        {
            response.sendRedirect("EmailConfirmation.jsp");   
        }}
        catch(Exception e)
        {
            out.print(e);
        }
    %>    
    </form>
    </div>

    </body>
    </html>

confirm.jsp中发生错误。我检查了邮件和uniquekeytxt都有数据。

1 个答案:

答案 0 :(得分:0)

在try catch块中包含此代码,然后您就可以了解一下。

try
{
String mail=session.getAttribute("mail").toString();
}
catch(NullPointerException e){}