网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月02日漏签0天
web吧 关注:123,114贴子:822,385
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 7回复贴,共1页
<<返回web吧
>0< 加载中...

web新人 求助 怎么写的项目出现空指针了 不知道怎么解决

  • 只看楼主
  • 收藏

  • 回复
  • 龙魔霸王
  • 托儿所
    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>


  • 龙魔霸王
  • 托儿所
    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>


2025-08-02 14:57:47
广告
不感兴趣
开通SVIP免广告
  • 龙魔霸王
  • 托儿所
    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);
}
}


  • 龙魔霸王
  • 托儿所
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
有大佬吗 查看了 jsp 就出现空指针问题


  • 龙魔霸王
  • 托儿所
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
顶


  • 小张小张,吃饭用缸
  • 托儿所
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
空指针是后端接口没接受到参数,打断点调试,还有最好截图问问题,不然不好看,我估计你这是学校交的吧,最原始的技术了


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 7回复贴,共1页
<<返回web吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示