๋ฐ์ํ
์๋ ํ์ธ์ yunamom ์ ๋๋ค
STEP 1 ์์๋ ๋ฐ์ดํฐ๊ฐ ๋์ด์์๋ ์ฝ์์ฐฝ์์ ์ถ๋ ฅ์ ํ์ธํ ์์์๋๋ฐ์
์ด๋ฒ์๊ฐ์๋ ๋ฐ์ดํฐ ํ๋ฉด์ถ๋ ฅ ํ๋๋ฒ์ ํฌ์คํ ํ๊ฒ ์ต๋๋ค.
๋จผ์ LoginPro.java ํ์ผ์ ์๋์ ๊ฐ์ด ์ฝ๋๋ฅผ ์ถ๊ฐ์์ฑํด์ฃผ์ธ์.
๐LoginPro.java ์ ์ฒด์ฝ๋
package com.test.web.controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/* form action ์ ์ด๋ฆ๊ณผ ์๋ ์ด๋
ธํ
์ด์
์ ์ด๋ฆ์ด ๊ฐ์์ผ ํฉ๋๋ค */
@WebServlet("/LoginPro.do")
public class LoginPro extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
requestPro(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
requestPro(request, response);
}
public void requestPro(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String pw = request.getParameter("pw");
System.out.println("์์ด๋ = " + id);
System.out.println("๋น๋ฐ๋ฒํธ = " + pw);
/* request ๊ฐ์ฒด์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ (๋ค์ํ์ด์ง๊น์ง ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ๊ฐ๋ค) */
request.setAttribute("id", id);
request.setAttribute("pw", pw);
/* LoginPro.jsp ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์ด๋ */
RequestDispatcher dis = request.getRequestDispatcher("LoginPro.jsp");
dis.forward(request, response);
}
}
๐ํ๋ฉด์ถ๋ ฅ์ ์ํด LoginPro.jsp ํ์ผ์ ์์ฑํ๊ฒ ์ต๋๋ค.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Pro</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="box">
<h3>์์ด๋ : ${ id }</h3>
<h3>๋น๋ฐ๋ฒํธ : ${ pw }</h3>
</div>
</div>
</body>
</html>
URL ์ ํ์ธํด๋ณด์๋ฉด LoginPro.do
์ค์ง์ ์ผ๋ก ์๋ฐ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ JSP ๋ก ์ถ๋ ฅ์ด ๋๋ ๋ชจ์ต์ ํ์ธํ์ค์์์ต๋๋ค.๐
์ด๋ฒ์๊ฐ์๋ ์ด๋ ๊ฒ ๊ฐ๋จํ๊ฒ ํ๋ฉด์ถ๋ ฅ ๋๋ ๋ชจ์ต๊น์ง ์ดํด๋ณด์์ต๋๋ค.
๊ธ์ ์ฝ์ด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค :)
300x250
'๊ฐ๋ฐ์ธ์ด > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JSTL] JSTL ๊ธฐ์ด ์ ๋ฆฌ (๋ฌธ๋ฒ / ์์ฑ๋ฒ) (0) | 2022.04.07 |
---|---|
[JSP/Servlet] css, js ์ ์ฉ์ด ์๋จ ํด๊ฒฐํ๊ธฐ (1) | 2022.04.05 |
[JSP] ๊ฒ์๊ธ ์ค๋ฐ๊ฟํ๊ธฐ - ( c:out / <pre> ํ๊ทธ ) (0) | 2022.03.30 |
JSP - ์๋ธ๋ฆฟ ๊ธฐ์ด ( model 2 ๋ฐฉ์ ) STEP 1 (0) | 2022.03.28 |
[JSP] ์๋ธ๋ฆฟ(Servlet) ์ด๋? (1) | 2022.03.23 |