package com.zsx.servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zsx.bean.User;
import com.zsx.utils.DBUtils;
/**
* Servlet implementation class FindAllServlet
*/
@WebServlet("/findAllServlet")
public class FindAllServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* 查询所有用户
*
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<User> userList = new ArrayList<User>(); // 创建一个list集合,用于装user集合
Connection conn = DBUtils.open(); // 打开数据库连接
String sql = " select id,user_name,password from user ;";
try {
PreparedStatement prtmt = conn.prepareStatement(sql);
ResultSet rs = prtmt.executeQuery();
while (rs.next()) {
int id = rs.getInt("id");
String username = rs.getString("user_name");
String password = rs.getString("password");
User user = new User(); /// 实例化user
user.setId(id);
user.setUserName(username);
user.setPasswrod(password);
userList.add(user);
}
request.setAttribute("userList", userList);
request.getRequestDispatcher("/user_list.jsp").forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtils.close(); // 关闭数据库连接
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
doGet(request, response);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jspServletDemo.zip (49个子文件)
jspServletDemo
.project 914B
.settings
.jsdtscope 567B
org.eclipse.wst.common.component 494B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
com
zsx
bean
User.java 741B
utils
DBUtils.java 2KB
servlet
UpdateServlet.java 2KB
FindAllServlet.java 2KB
DelServlet.java 2KB
AddServlet.java 2KB
FindOneServlet.java 2KB
jdbc.properties 134B
build
classes
com
zsx
bean
User.class 1KB
utils
DBUtils.class 2KB
servlet
DelServlet.class 2KB
FindOneServlet.class 3KB
AddServlet.class 3KB
UpdateServlet.class 3KB
FindAllServlet.class 3KB
jdbc.properties 134B
WebContent
WEB-INF
web.xml 654B
lib
mysql-jdbc.jar 524KB
jstl-1.0.2.jar 20KB
standard.jar 403KB
index.jsp 343B
META-INF
MANIFEST.MF 39B
resource
bs
css
bootstrap.min.css 118KB
bootstrap.css.map 380KB
bootstrap-theme.min.css.map 25KB
bootstrap.min.css.map 529KB
bootstrap-theme.css.map 47KB
bootstrap-theme.css 26KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
fonts
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.eot 20KB
js
jquery-1.11.1.js 276KB
npm.js 484B
bootstrap.js 68KB
bootstrap.min.js 36KB
user_list.jsp 5KB
.classpath 842B
jspdemo.sql 1KB
共 49 条
- 1
资源评论
- sotup2020-08-10真的非常好用,谢谢分享
一抹茶-csdn
- 粉丝: 1128
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功