데이터베이스 WebDatabase

Alpha, Orderly·2023년 11월 9일
0

데이터베이스

목록 보기
8/13

JSP / Java Server Page

  • 클라이언트의 요청에 따라 동적으로 서버에서 웹사이트를 생성해 응답한다.
  • JDBC를 이용해 데이터베이스 서버와 연결한다.
  • 자바를 사용한다.

Apache Tomcat

  • JSP를 호스팅하는 프로그램

JSP

자바 코드 넣기

  • 태그 안에 <% {} %> 를 넣어 중괄호 자리에 자바 코드를 넣을수 있다.

데이터베이스 서버를 연결하고 쿼리를 실행하는 예시

쿼리의 결과를 받아 테이블 형식으로 html에 동적으로 생성하는 예시

기타 지시자

<%@ %>

  • jsp와 관련된 속성을 정의할때 사용한다.

<%! %>

  • 서블릿 클래스의 변수, 메소드를 선언시 사용한다.

<%= %>

  • 변수 자체를 html에 대입하기 위해 사용한다.

JSP 문법

html 코드 입력하기 - out.println("입력할 html")

라이브러리 import

  • 최상단에 <%@ page %> 안에 import 문 넣기
  • 콤마( , ) 를 통해 여러개의 라이브러리를 가져올수 있다.

HTML 문법

table

  • table : 테이블
  • tr : 테이블 행
  • th : 테이블 헤더 열
  • td : 헤더가 아닌 열

form

  • action : 연결될 주소
  • method : GET, POST 등의 method

input

  • name으로 입력값을 구분할수 있다.
    • POST의 경우 request.getParameter(name), GET의 경우 request.getQueryString(name)으로 받는다.
  • radio input의 경우 동일 그룹은 같은 name을 가져야 한다.
    		<form method="POST" action="getYourData.jsp">
    				<label for="first_name">First Name: <input type="text" name="first_name"></label>
    				<label for="last_name">Last Name: <input type="text" name="last_name"></label>
    				<label for="student_id">studentID: <input type="text" name="student_id"></label> 
    				<h4>Select which section you are taking:</h4>
    				<div class="radio_buttons">
    					<input type="radio" name="section" value="COMP32202">COMP32202</input>
    					<input type="radio" name="section" value="COMP32203">COMP32203</input>
    					<input type="radio" name="section" value="COMP32204">COMP32204</input>
    					<input type="radio" name="section" value="COMP32205">COMP32205</input>
    					<input type="radio" name="section" value="Nothing">Nothing</input>
    				</div>
    				<button type="submit">Submit</button>
    			</form>
profile
만능 컴덕후 겸 번지 팬

0개의 댓글