web新人 求助 怎么写的项目出现空指针了 不知道怎么解决
web吧
全部回复
仅看楼主
level 1
龙魔霸王 楼主
index.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/2/17
Time: 15:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<a href="customer.jsp">
<button>客户列表</button>
</a>
</body>
</html>
customer.jsp
<%@ page import="java.util.List" %>
<%@ page import="org.th.customer" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/2/17
Time: 14:48
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>客户列表</title>
</head>
<servlet>
<servlet-name>list</servlet-name>
<servlet-class>list</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>list</servlet-name>
<url-pattern>/list</url-pattern>
</servlet-mapping>
<body>
<h1>客户列表</h1>
<%
List<customer> customers=(List<customer>) request.getAttribute("customers");
%>
<table border="1">
<thead>
<tr>
<th>cust_id</th>
<th>cust_name</th>
<th>email</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<%
int a;
for(a=0;a<customers.size();a++){
%>
<tr>
<td><%=customers.get(a).getId()%></td>
<td><%=customers.get(a).getName()%></td>
<td><%=customers.get(a).getEmail()%></td>
<td><input type="button" value="删除" class="delete" >/<input type="button" value="修改" class="updata" ></td>
</tr>
<%
}
%>
</tbody>
</table>
</body>
</html>
2020年02月19日 07点02分 1
level 1
龙魔霸王 楼主
customer.class
<%@ page import="java.util.List" %>
<%@ page import="org.th.customer" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/2/17
Time: 14:48
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>客户列表</title>
</head>
<servlet>
<servlet-name>list</servlet-name>
<servlet-class>list</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>list</servlet-name>
<url-pattern>/list</url-pattern>
</servlet-mapping>
<body>
<h1>客户列表</h1>
<%
List<customer> customers=(List<customer>) request.getAttribute("customers");
%>
<table border="1">
<thead>
<tr>
<th>cust_id</th>
<th>cust_name</th>
<th>email</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<%
int a;
for(a=0;a<customers.size();a++){
%>
<tr>
<td><%=customers.get(a).getId()%></td>
<td><%=customers.get(a).getName()%></td>
<td><%=customers.get(a).getEmail()%></td>
<td><input type="button" value="删除" class="delete" >/<input type="button" value="修改" class="updata" ></td>
</tr>
<%
}
%>
</tbody>
</table>
</body>
</html>
2020年02月19日 07点02分 2
level 1
龙魔霸王 楼主
list.class
package org.th;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class list extends HttpServlet {
@Override
public void init() throws ServletException {
String message="客户列表";
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<customer> customers=new ArrayList<customer>();
customer c1=new customer("1","2","3","4","5");
customers.add(c1);
// String user = "root";
// String password ="root";
// String url ="jdbc:mysql://localhost:3306/customer?useEncod=true&characterEncoding=utf8";
// String driverClass = "com.mysql.jdbc.Driver";
// String sql="select * from customer";
// //3.加载驱动
// Connection conn=null;
// Statement stmt=null;
// ResultSet rs=null;
// try {
// Class.forName(driverClass);
// conn = DriverManager.getConnection(url,user,password);
// System.out.println(conn);
// stmt = conn.createStatement();
// rs=stmt.executeQuery(sql);
// while(rs.next()){
// customer temp=new customer(rs.getString("cust_id"), rs.getString("cust_name"),rs.getString("email"),rs.getString("birth"),rs.getString("photo"));
// customers.add(temp);
// }
// } catch (ClassNotFoundException | SQLException e) {
// e.printStackTrace();
// }finally{
// try {
// conn.close();
// stmt.close();
// rs.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// }
req.setAttribute("customers",customers);
req.getRequestDispatcher("/list.jsp").forward(req,resp);
}
}
2020年02月19日 07点02分 3
level 1
龙魔霸王 楼主
有大佬吗 查看了 jsp 就出现空指针问题
2020年02月19日 07点02分 4
level 1
龙魔霸王 楼主

2020年02月19日 07点02分 5
level 1
空指针是后端接口没接受到参数,打断点调试,还有最好截图问问题,不然不好看,我估计你这是学校交的吧,最原始的技术了
2020年02月19日 08点02分 6
老哥 怎么断点调试 不太懂 , 麻烦 老哥你了 能 教我一下吗 现在在跟老师学 这里卡主了 后面 就学不动了
2020年02月20日 06点02分
你开发工具里面可以直接打断点的,或者你不会打断点,就在java那个接口那输出页面传来的值,这里面应该没传过来,是空的,所以报空指针了
2020年02月21日 02点02分
1