본문 바로가기
자바 풀스택 공부

Day 50. [JSP/Servlet] 커스텀 태그

by seung_nari 2022. 3. 18.

커스텀 태그

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
	//request.setAttribute("request", request);
%>

<form method="post">
	<button formmethod="get">GET 전송</button>
	<button>POST 전송</button>
</form>
<h2><%=request.getMethod() %></h2>
<h2>request.setAttribute() : ${request.method}</h2>
<h2>pageContext 내장 객체 접근 : ${pageContext.request.method}</h2> <!-- 내장 객체 접근 pageContext -->

<!-- c:if를 이용해 GET > 겟 출력 POST 포스트 출력 -->
<%
	if(request.getMethod().equals("GET")){
		out.println("<h2>겟<h2>");
	}
	if(request.getMethod().equals("POST")){
		out.println("<h2>포스트<h2>");
	}
%>
<c:if test="${pageContext.request.method=='GET'}">
	<h2>if : ${pageContext.request.method}</h2>
</c:if>
<c:if test="${pageContext.request.method=='POST'}">
	<h2>if : ${pageContext.request.method}</h2>
</c:if>

<c:choose>
	<c:when test="${pageContext.request.method=='GET'}">
		<h2>when : ${pageContext.request.method}</h2>
	</c:when>
	<c:when test="${pageContext.request.method=='POST'}">
		<h2>when : ${pageContext.request.method}</h2>
	</c:when>
</c:choose>
</body>
</html>

 

 

 

 


회원가입

> memberDao 만 수정!
> 입력한 글자가 포함된 이름만 보여주기

 

public List<MemberVo> list(String keyword) {
		List<MemberVo> list = new ArrayList<>();
		
		try {
			conn = DBConn.getConnection();
			String query = "SELECT * FROM T_MEMBER";
			
//			keyword = "홍길동"; >> LIKE '%"홍길동"%';
			if(keyword != null && !keyword.isEmpty()) {
				query += " WHERE NAME LIKE '%' || ? || '%'";
			}
			
			pstmt = conn.prepareStatement(query); // 전처리 시킴
			
			if(keyword != null && !keyword.isEmpty()) {
				pstmt.setString(1, keyword);
			}
						
			ResultSet rs = pstmt.executeQuery();
			
			while(rs.next()) {
				int idx = 1;
				MemberVo vo = new MemberVo(
						rs.getString(idx++),
						rs.getString(idx++),
						rs.getString(idx++),
						rs.getString(idx++),
						rs.getDate(idx++)
						);
				list.add(vo);
			}
			rs.close();
			pstmt.close();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}

댓글