Nov 10 : What is JSP

Kim·2020년 11월 10일
0

JSP

목록 보기
1/5
post-thumbnail

📌 JSP

Java Server Page

  • JSP = HTML/CSS + additional built-in objects(client codes and server codes are mixed)
    JSP can connect to Oracle and MySQL
    JSP태그(<%%>)가 먼저 실행된 후에 html이 실행.
    최근에는 섞어쓰지 않고 servlet에서 html을 호출하며 작성하는 일이 많음.

    Spring framework based on Java >> JSP

web browser > web server
JSP/Java > web server
그러면 web server가 프로그램을 처리함

HTML/CSS/Javscript > web server > web browser
Through web server, HTML/CSS/Javascript can send data to web browser directly.



📌 Survlet

Small server programs don't have public static void main() (main method).
.java file.
out.println can be used in servlet only one time

  • Create survlet

📌 Get and Post

  • ⛄ Get

    www.google.com?key=value&key1=value2
    Get key ~ value2(QueryString) and send the data to the web server.
    Write the get method then you can call post method through ajax.

  • ⛄ Post

    www.google.com + packet(hidden data)
    post method is safer than get method

📌 URL structure

web server address : port number / program name?parameter lists

https://velog.io/@kiiim
https://velog.io = web server address
@kiiim = parameter

웹서버주소:포트번호/프로그램 이름(=servlet)?매개변수리스트(key1=val1&key2=val2)

📌 JSP 활용

Practically it is almost like CSS/HTML + some Java functions.

Create survlet first!

어떤 ✌변수✌를 웹페이지에 넣어주고 싶으면 <% %>로 묶으면 됨
그래야만 서버에서 변수 값을 가져오고 웹페이지에 출력됨!
<% %> JSP와 HTML을 분리해주기 위해 사용
HTML/CSS 태그들은 묶지 않아도 괜찮음

<body>
<% //java program (Works in server)
	int num1=20;
	int num2=10;
	int add=num1+num2;
%>
<%=num1%>+<%=num2%>=<%=add%> 
//<%=num1%> (Bring the value of num1)
  • ⛄ practice

    구구단 단별로 한 테이블씩 출력
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Addition</title>
</head>
<style>
td {
width:100px;height:50px;text-align:center;
}
</style>
<body>
<% // java(in server)
	for(int i=2; i<10; i++){
%>
<table border=1> // html/css don't need to execute in server
<% // java
	for(int j=1; j<10; j++){
	int n=i*j;
%>		
<tr><td><%=i%>*<%=j%>=<%=n%></td></tr> // html/css tag wrap variable
<%
		} // java (for)
%>
</table><br> // close table tag(html)
<%
	} // java
%>
</body>
</html>

<table>태그 열고 닫는거 주의!

0개의 댓글