๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java·๏ปฟServlet·๏ปฟJSP

์ดํด๋ฆฝ์Šค์—์„œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๋ฐ ๋ฐฐํฌํ•˜๊ธฐ

by Leica 2020. 2. 2.
๋ฐ˜์‘ํ˜•

ํ™˜๊ฒฝ ๋ฐ ๋ฒ„์ „

  1. ํ”Œ๋žซํผ(OS) : Windows 64-bit
  2. JDK : OpenJDK - Amazon Corretto 11
  3. Eclipse : Eclipse IDE for Enterprise Java Developers 2019-12
  4. Tomcat : 9.0.30

 

1. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

File - New - Project...๋ฅผ ์„ ํƒํ•œ๋‹ค.

 

Web - Dynamic Web Project๋ฅผ ์„ ํƒํ•˜๊ณ  [Next >]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

๋˜๋Š”

 

New - Dynamic Web Project๋ฅผ ์„ ํƒํ•œ๋‹ค.

 

โ€ป ์ดํด๋ฆฝ์Šค์˜ Dynamic Web Project ํ”„๋กœ์ ํŠธ ์œ ํ˜•์€ ์„œ๋ธ”๋ฆฟ ๋ฐ JSP ๊ธฐ๋ฐ˜ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

 

Project name์„ ์ž…๋ ฅํ•˜๊ณ  Target runtime์— ๋ฐฐํฌํ•  ์„œ๋ฒ„๋ฅผ ์„ ํƒํ•œ๋‹ค.

Tomcat์„ ๋ฏธ๋ฆฌ ์„ค์น˜ํ•˜๊ณ  ์ดํด๋ฆฝ์Šค์™€ ์—ฐ๋™์‹œ์ผœ๋‘์–ด์•ผ ํ•œ๋‹ค.

[Finish]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

์ฐธ๊ณ  :

JAVA ์›น ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• - Eclipse + JDK + Tomcat ์„ค์น˜ ๋ฐ ์—ฐ๋™

 

JAVA ์›น ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• - Eclipse + JDK + Tomcat ์„ค์น˜ ๋ฐ ์—ฐ๋™

์‹œ์ž‘ํ•˜๋ฉฐ ๋ณธ ํฌ์ŠคํŒ…์—์„œ๋Š” Windows 64-bit ํ”Œ๋žซํผ์„ ๊ธฐ์ค€์œผ๋กœ ํ•˜๋ฉฐ ์•„๋ž˜์˜ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ๋‹ค. JDK : OpenJDK - Amazon Corretto 11 Eclipse : Eclipse IDE 2019-12 R Packages Tomcat : 9.0.30 1. JDK ๋‹ค์šด๋กœ๋“œ ๋ฐ..

atoz-develop.tistory.com

 

2. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ž‘์„ฑ

์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๋ฉด ใ…‡ใ…‡ใ…‡๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”. ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฐ„๋‹จํ•œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž‘์„ฑํ•˜์˜€๋‹ค.

 

web01 ํ”„๋กœ์ ํŠธ

 

(1) IntroServlet.java

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;

@WebServlet("/intro")
@SuppressWarnings("serial")
public class IntroServlet extends GenericServlet {
	
	@Override
	public void service(
			ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.println(name + "๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”.");
	}

}

 

(2) index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.</h1>
<form action="intro" method="post">
<input type="text" name="name" style="width: 50px;">
<input type="submit" value="Submit">
</form>
</body>
</html>

 

3. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐ์น˜

๋ฐฐ์น˜(Deployment)

์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ํ†ฐ์บฃ ์„œ๋ฒ„์— ๋ฐฐ์น˜(deployment) ํ•ด์•ผํ•œ๋‹ค. ๋ฐฐ์น˜๋ž€ ํด๋ผ์ด์–ธํŠธ์—์„œ ์„œ๋น„์Šค๋ฅผ ์š”์ฒญํ–ˆ์„๋•Œ ํ†ฐ์บฃ ์„œ๋ฒ„๊ฐ€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

Servers ๋ทฐ

Servers ๋ทฐ์˜ ํ†ฐ์บฃ ์„œ๋ฒ„๋ฅผ ๋”๋ธ”ํด๋ฆญํ•˜๊ฑฐ๋‚˜ ์ปจํ…์ŠคํŠธ ๋ฉ”๋‰ด์—์„œ [Open]์„ ํด๋ฆญํ•˜์—ฌ ์„œ๋ฒ„ ์„ค์ •์ฐฝ์„ ์—ฐ๋‹ค.

 

์„œ๋ฒ„ ์„ค์ •์ฐฝ

Modules ํƒญ์„ ์„ ํƒํ•˜๊ณ  [Add Web Modules...]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

์›น ๋ชจ๋“ˆ ๋“ฑ๋ก์ฐฝ

์›น ๋ชจ๋“ˆ์„ ์„ ํƒํ•œ๋‹ค. Path๋Š” ๋ชจ๋“ˆ์„ ์„ ํƒํ•˜๋ฉด ๋™์ผํ•œ ์ด๋ฆ„์œผ๋กœ ์ž๋™์œผ๋กœ ์ž…๋ ฅ๋œ๋‹ค. Path๋Š” ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ด๋ฆ„์ด๋ฉฐ ์›น ๋ธŒ๋ผ์šฐ์ €๋Š” ์ด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์—ฌ ํ†ฐ์บฃ ์„œ๋ฒ„์— ์„œ๋น„์Šค๋ฅผ ์š”์ฒญํ•œ๋‹ค. ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

[OK]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

File - Save ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ•˜๊ฑฐ๋‚˜ Ctrl + s๋ฅผ ๋ˆŒ๋Ÿฌ ์ €์žฅํ•˜๋ฉด ํ†ฐ์บฃ ์„œ๋ฒ„์— ์ƒˆ๋กœ์šด ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ชจ๋“ˆ์ด ๋“ฑ๋ก๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ†ฐ์บฃ์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•œ๋‹ค.

 

4. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰

 

์ด์ƒ์œผ๋กœ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์ดํด๋ฆฝ์Šค์—์„œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์•˜๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€