전체 글
-
mysql에서 데이터 가져오기JSP 2023. 3. 23. 12:44
mysql의 board 테이블에는 다음과 같은 데이터가 저장되어 있다. JSP에서 해당 DB에 연결하고 데이터를 가져와보자. - java.sql을 import하고 테이블의 헤더가 될 부분을 작성했다. 이후 conn, rs, stmt 객체를 생성해서 서버를 연결할 준비를 했다. - 서버 연결을 확인할 수 있는 try-catch문에 서버를 연결시키는 실행문을 작성하고 데이터를 가져오기 위해 while 문 내부에 rs.next() 함수를 실행시켰다. .next() 함수는 첫 번째 열의 첫 번째 행에서부터 아래로 내려가면서 데이터가 있으면 true를 반환하고 데이터가 없으면 false를 반환한다. 이후에 HTML 문법으로 테이블을 작성하고 데이터베이스 내부의 값을 가져왔다. - catch , finally 문을..
-
프론트엔드와 백엔드 / JDBC 세팅JSP 2023. 3. 23. 10:22
웹 개발은 프론트엔드와 백엔드로 나눌 수 있다 프론트엔드 : html - css - javaScrpit - server 전체를 프론트엔드라고 하고 유저가 웹 페이지를 이용하고, 데이터를 서버를 통해 백엔드로 보내는 역할을 한다. JSP 를 이용하면, 위의 4가지 역할을 모두 할 수 있다. 백엔드 : JAVA - Database 프론트엔드에서 서버로 보낸 데이터를 받아서 구분하고 저장할 수 있다. 자바와 데이터베이스를 연결하는 것을 JDBC 라고 한다. (최근에는 ODBC 라고 많이 한다 - 자바대신 오라클을 이용) JDBC 세팅 - mySQL 사이트의 다운로드 - MySQL Comunity (GPL) Download 로 이동한다. - 자바와 연결 할 것이기 때문에 Connector/J 를 선택 - ope..
-
c: 코어태그 와 fmt: 국제화 태그JSP 2023. 3. 23. 09:40
라이브러리 추가하기 코어태그와 국제화 태그를 사용하려면 WEB-INF 폴더 -> lib 폴더에 .jar 파일을 추가하고 taglib 선언을 해야한다. c: 코어태그 : 코어 태그 라이브러리는 변수 설정이나 if-else 같은 논리 처리에 사용되는 스크립트 코드를 대체하는 태그를 제공한다. - JSP 페이지에 taglib 디렉티브가 꼭 필요하다. c:if 태그 - c:if 태그와 ${ } 의 사용 예이다. 1, 2번 태그는 True라서 텍스트를 출력하지만, 3번째 태그는 False라서 텍스트를 출력하지 않는다. 일반적인 if 와 다르게, c:if 는 else나 else가 불가능하다. , , : 자바의 switch 구문과 if-else 구문을 혼합한 형태로서, 다수의 조건문을 하나의 블럭에서 수행할 때 사용..
-
api response와 async 함수, awaitReact 2023. 3. 22. 15:12
async 함수 : 비동기 함수 ( 호출 시점에서 실행결과를 기다리지 않는 함수 ) -> 자바스크립트의 경우 single thread 기반 언어이기 때문에, 한 번에 하나의 작업이 가능하다. 하지만 비동기 함수를 사용하면 함수의 실행결과를 기다리지 않고 다른 작업을 수행하기 때문에 브라우저에 화면이 병렬적으로 로딩되게 만들 수 있다. ( 동기함수의 하나의 작업이 끝나지 않으면 화면이 멈출 수 있음 ) async function 함수명() { return something; } : async는 function 앞에 위치할 수 있으며, async 가 붙은 함수는 항상 프라미스를 반환한다. 프라미스가 아닌 값이라면, 이행 상태의 프라미스로 값을 감싸서 이행된 프라미스가 되도록 만든다. await : async..
-
세션 (session)JSP 2023. 3. 22. 12:41
세션 이란? : 쿠키가 클라이언트 측의 데이터 보관소라면 세션은 웹 브라우저와 관련된 정보를 저장하는 장소이다. 세션으로 로그인 만들기 - if 문으로 조건을 확인한 뒤 session.setAttribute("세션속성명" , 값) 을 선언한 것으로 session에서 로그인 처리가 완료된 것이다. ** 이때 저장된 Attribute를 불러올때 getAttribute("세션속성명") 을 선언하면 Object 형태로 리턴값이 온다는 것을 명심하자 로그인 확인 - getAttribute의 타입을 고려해서 String으로 변환하고 memberId 가 있음을 확인하는 것으로 로그인 되었음을 알 수 있다. 로그아웃 로그아웃 처리 session.invalidate(); -> 현재 세션에서 로그아웃 한다. session..
-
쿠키 (cookie)JSP 2023. 3. 22. 12:04
쿠키 란? : 웹 브라우저가 보관하는 데이터이다. 웹 브라우저는 웹 서버에 요청을 보낼 때 쿠키를 함께 전송하며, 웹 서버는 웹 브라우저가 전송한 쿠키를 사용해서 필요한 데이터를 읽을 수 있다. 쿠키는 웹 서버와 웹 브라우저 양쪽에서 생성할 수 있다. ** 쿠키는 내 컴퓨터에 저장되기 때문에 웹 브라우저가 닫힌다고 해도 사라지지 않는다. ** 쿠키는 보안이 좋은편은 아니다 쿠키 동작 방식 1. 쿠키 생성 : 웹 브라우저에서 웹 서버에 쿠키 생성을 요청한다 -> 웹 서버가 생성한 쿠키를 데이터의 헤더에 저장해서 웹 브라우저에 전송한다. 2. 쿠키 저장 : 웹 브라우저는 쿠키를 저장소에 보관한다. 쿠키의 종류에 따라 메모리나 파일에 저장한다 3. 쿠키 전송 : 웹 브라우저는 저장한 쿠키를 요청이 있을 때마다..
-
자바빈 , <jsp:useBean> 액션 태그JSP 2023. 3. 22. 10:32
자바빈 : 속성(데이터) , 변경 이벤트 , 객체 직렬화를 위한 표준 -> 회원의 정보를 받아올 때 정보에 대한 제약을 주기 위함 1. 자바빈 클래스 생성 : JSP 프로젝트 속의 Java Resources 폴더에 MemberInfo 파일을 생성해보자. - 패키지 생성 후, MemberInfo 파일을 만들고 원하는 데이터의 저장공간을 생성했다. Source 탭 -> Generate Getter and Setter 를 클릭해서 Getter와 Setter를 자동 생산할 수 있다. 2. 액션태그를 사용해 객체 생성 : 자바빈 객체를 지정할 때 액션태그의 기본 구문 id : JSP 페이지에서 자바빈 객체에 접근할 때 사용할 이름을 지정한다. class : 패키지 이름을 포함한 자바빈 클래스의 완전한 이름을 입력..