hwi
78
2019-04-29 22:53:56
0
158

자바빈을 활용한 주소록에서 삭제 부분을 만들려고 합니다.


DB는 쓰지않고 ArrayList에 값을 저장해서 빼오는 형식으로 하려고 합니다만

만든 주소록을 삭제 부분에서 도저히 감이 잡히지가 않습니다..


addr_list.jsp에서 delete.jsp로 유저아이디 값을 넘기고

AddrManager.java에서 delete 함수를 불러오면 될것 같은데..


힌트 좀 주시면 감사하겠습니다 ㅜㅜ

 



addr_list.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="jspbook.ch07.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="addr" class="jspbook.ch07.AddrBean"/>

<jsp:useBean id="addr2" class="jspbook.ch07.AddrBean2"/>

<jsp:setProperty name="addr" property="*"/>

<jsp:useBean id="am" class="jspbook.ch07.AddrManager" scope="application"/>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>ch07 : 주소록 목록</title></head>

<body>

<div align=center>

<H2>주소록</H2>

<HR>

<a href="addr_form.html">주소추가</a>

<P>

<table border=1 width=500>

<tr>

<td>이름</td>

<td>전화번호</td>

<td>이메일</td>

<td>성별</td>

</tr>

<%

for(AddrBean ab : am.getAddrList()) {

%>

<tr>

<td><%=ab.getUsername() %></td>

<td><%=ab.getTel() %></td>

<td><%=ab.getEmail() %></td>

<td><%=ab.getSex() %></td>

<td><a href="delete.jsp?id=<%=ab.getUsername()%>">삭제</a></td>

//<td><a href="delete.jsp?id=<%=ab.getUsername()%>">수정</a></td>

</tr>

<%

}

%>

</table>

<input type="button" value="삭제" onClick="javascript:window.location='delete.jsp'" />

<input type="button" value="수정" onClick="javascript:window.location='delete.jsp'" />

</div>


</body>

</html>



delete.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="jspbook.ch07.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="am" class="jspbook.ch07.AddrManager" scope="application"/>
<jsp:useBean id="addr" class="jspbook.ch07.AddrBean"/>
<jsp:setProperty name="addr" property="*"/>
<%

    String id = request.getParameter(id);
    am.remove(addr);   

    //response.sendRedirect("addr_list.jsp");

%>

</body>
</html>



AddrManager.java


package jspbook.ch07;
import java.util.ArrayList;
import java.util.List;
/** File : AddrManager.java Desc : 주소록 관리 클래스 */
public class AddrManager {
List<AddrBean> addrlist = new ArrayList<AddrBean>();
List<AddrBean2> addrlist2 = new ArrayList<AddrBean2>();
public void add(AddrBean ab) {
addrlist.add(ab);
}
public void remove(AddrBean ab) {
addrlist.remove(ab);
}
// (javabean에서)만들어져 있는 것을 돌려받음
public List<AddrBean> getAddrList() {
return addrlist;
}
// 있는지 없는지 판단
    public AddrBean getAddr(String username) {
for(AddrBean ab : addrlist) {
if(ab.getUsername().equals(username))
return ab;
}
return null;
}
   
}



0
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.