티스토리 뷰
welcome.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<h2>안녕하세요!</h2>
<a href="log.jsp">로그인</a>
<br>
<a href="add_log.jsp">회원가입</a>
<br>
<a href="update_log.jsp">정보수정</a>
<br>
<a href="./all.do">모든 회원 정보 확인</a>
</body>
</html>
login_controller.java 추가구문
else if(command.equals("/all.do")) {
String id = request.getParameter("id");
System.out.println("아이디 : "+id);
String passwd = request.getParameter("passwd");
System.out.println("비번 : "+passwd);
String name = request.getParameter("name");
System.out.println("이름 : "+name);
all_info dao = all_info.getInstance();
List<memberdto> member = dao.all();
request.setAttribute("member", member);
RequestDispatcher rd = request.getRequestDispatcher("all_membershow.jsp");
rd.forward(request, response);
}
all_info.java
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import database.dbconnect;
import dto.memberdto;
public class all_info {
private Connection dbconn;
private static all_info instance;
private all_info() {
}
public static all_info getInstance() {
if(instance == null) {
instance = new all_info();
}
return instance;
}
public List<memberdto> all() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<memberdto> memberlist = new ArrayList<>();
String sql = "select * from info";
try {
conn = dbconnect.getConnection();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
String id= rs.getString("id");
String passwd= rs.getString("passwd");
String name= rs.getString("name");
memberdto member = new memberdto();
member.setId(id);
member.setPasswd(passwd);
member.setName(name);
memberlist.add(member);
}
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
} catch(SQLException e) {
e.printStackTrace();
}
}
return memberlist;
}
}
memberdto.java
package dto;
public class memberdto {
private String id;
private String passwd;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
all_membershow.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="dto.memberdto" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<h2>모든 회원 정보 조회</h2>
<%
List<memberdto> member = (List<memberdto>) request.getAttribute("member");
for(int i=0; i<member.size(); i++){
memberdto currentMember = member.get(i);
out.println((i+1)+"번째");
%>
<p>
ID: <%= currentMember.getId() %><br>
Password: <%= currentMember.getPasswd() %><br>
Name: <%= currentMember.getName() %><br>
</p>
<%
}
%>
</body>
</html>
'코딩 > JSP' 카테고리의 다른 글
[13주 1일차] [쉽게 배우는 JSP 웹 프로그래밍 연습문제] 5장 (0) | 2024.01.01 |
---|---|
[12주 5일차] SendRedirect & forward (0) | 2023.12.29 |
[12주 4일차] 미니 프로젝트 (0) | 2023.12.28 |
[12주 3일차] 웹 쇼핑몰 분석 (1) | 2023.12.27 |
URI / contextPath / substring (0) | 2023.12.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday