| |

VerySource

 Forgot password?
 Register
Search
View: 800|Reply: 5

Please masters to solve this JSP problem

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 16:10:01
| Show all posts |Read mode
This code, the error when I execute it is as follows;
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:248)
javax.servlet.http.HttpServlet.service (HttpServlet.java:856)
root cause
java.lang.NullPointerException
bean.jdbcBean.closeDB (jdbcBean.java:41)
org.apache.jsp.checkout_jsp._jspService (checkout_jsp.java:172)
org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service (HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:248)
javax.servlet.http.HttpServlet.service (HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
Source:
<% @ page contentType = "text / html; charset = gb2312" language = "java" import = "java.sql. *" errorPage = ""%>
<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = gb2312">
<title> Online Disc Store: Discs Endlessly </ title>
</ head>
<body>
<% @ include file = "header.jsp"%>
<table width = "800" height = "400" border = "1" align = "center">
  <tr>
    <td> <%
Vector buylist = (Vector) session.getValue ("shopcar");
if (buylist == null | buylist.size () <1)
{
%>
<jsp: forward page = "mydisk.jsp"> </ jsp: forward>
<%}
String userid = (String) session.getValue ("uid");
float pricenum = 0;
for (int i = 0; i <buylist.size (); i ++)
{
Disk disk = (Disk) buylist.elementAt (i);
pricenum = pricenum + disk.getBuynum () * disk.getPrice ();
}
Ransom
jdbcBean diskBean1 = new jdbcBean ();
String sql1 = "INSERT INTO myorder (user_id, price_num, order_time) VALUES ('" + userid + "'," + pricenum + ", '" + current_time + "')";
int m = diskBean1.executeUpdate (sql1);
diskBean1.closeDB ();
jdbcBean diskBean2 = new jdbcBean ();
String sql2 = "SELECT order_id FROM myorder WHERE order_id = '" + userid + "' AND order_time = '" + current_time + "'";
ResultSet rs = diskBean2.executeQuery (sql2);
rs.next ();
String orderid = rs.getString ("order_id");
diskBean2.closeDB ();
Ransom
for (int j = 0; j <buylist.size (); j ++)
{
Disk disk = (Disk) buylist.elementAt (j);
jdbcBean diskBean3 = new jdbcBean ();
String sql3 = "INSERT INTO orderitem (order_id, sno, disk_num) VALUES ('" + orderid + "', '" + disk.getSno () + "', '" + disk.getBuynum () + "')";
int mm = diskBean3.executeUpdate (sql3);
diskBean3.closeDB ();
}
%> </ td>
  </ tr>
   </ table>
 <% @ include file = "footer.jsp"%>
</ body>
</ html>

I have included the required packages in header.jsp <% @ page import = "java.io. *"%>
<% @ page import = "java.util. *"%>
<% @ page import = "java.sql. *"%>
<% @ page import = "java.text. *"%>
<% @ page import = "bean. *"%>
The above code is wrong, but it can still insert data into the data table myorder, I look forward to your help !!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-6 19:42:01
| Show all posts
I do n’t know. Which master clicked it?
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-6 19:54:01
| Show all posts
Null pointer exception, NullPointerException
Take a look at your closeDB method. Is the connection open?
Debug your statements step by step to see which variables are not assigned a value.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-7 09:57:01
| Show all posts
This is your ResultSet rs; you have not used rs or you have closed rs.close ()
Reply

Use magic Report

1

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-8 09:54:01
| Show all posts
Step-by-step debugging, don't write it all at once
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-10 17:54:01
| Show all posts
First of all, thank you,woaiyan2andzslinke, I have paid attention to my situation, public void closeDB () {
         try {
           if (rs! = null) rs.close ();
         }
         catch (Exception e) {
           e.printStackTrace (System.err);
         }
         try {
           if (stmt! = null) stmt.close ();
         }
         catch (Exception e) {
           e.printStackTrace (System.err);
         }
         try {
           if (conn! = null) {
             conn.close ();
           }
         }
         catch (Exception e) {
           e.printStackTrace (System.err);
         }
       }
I used this function, but the problem is still the same as before, and I still look forward to your help. By the way, I recommend a tool that can gradually debug JSP. I use Dreamweaver now.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list