๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ์–ธ์–ด/JSP

JSP - ์„œ๋ธ”๋ฆฟ ๊ธฐ์ดˆ ( model 2 ๋ฐฉ์‹ ) STEP 2

by yunamom 2022. 3. 28.
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” 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 ๋กœ ์ถœ๋ ฅ์ด ๋˜๋Š” ๋ชจ์Šต์„ ํ™•์ธํ•˜์‹ค์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.๐Ÿ˜Š

LoginPro.do

 

์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” ์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ™”๋ฉด์ถœ๋ ฅ ๋˜๋Š” ๋ชจ์Šต๊นŒ์ง€ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

๊ธ€์„ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)

300x250

์ฝ”๋“œ