V 41일차 - JSP 입문

박태은·2024년 8월 5일

V 웹개발자 프로젝트

목록 보기
42/59

data-lightbox="image-1"
사진 확대 보이기
JS!

인텔리제이 IDE

자바
DBMS -> mysql
자바 + DBMS -> JDBC


package com.KoreaIT.java.jsp_AM;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


@WebServlet("/home/printDan")
public class HomePrintDan extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.getRequestDispatcher("/jsp/home/printDan.jsp").forward(request, response);
	}
}

스프링부트 자바 파일

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
int dan = Integer.parseInt(request.getParameter("dan"));
int limit = Integer.parseInt(request.getParameter("limit"));
String color = request.getParameter("color");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단 출력</title>
</head>
<body>
	<h1>
		<div style="color:<%=color%>">==<%=dan%>단==</div>
	</h1>
	<%
	for (int i = 1; i <= limit; i++) {
	%>
	<div style="color:<%=color%>"><%=dan%>
		*
		<%=i%>
		=
		<%=dan * i%></div>
	<%
	}
	%>
</body>
</html>

JSP 파일

위 두개가 합쳐져 입력된대로 바뀌는 구구단 사이트가 나옴.

profile
취업준비생. 웹개발자를 목표로.

0개의 댓글