<코드>
home
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<style>
button{
background-color:rgba(0, 0, 0, 0);
color:rgb(175, 131, 131);
border: 1px solid rgb(175, 131, 131);
border-radius: 5px;
}
button:hover{
color: white;
background-color: rgb(175, 131, 131);
}
table{
margin-left: auto;
margin-right: auto;
margin-top:300px;
background-color:rgb(248, 226, 198);
border: 5px solid rgb(248, 226, 198);
border-radius: 10px;
box-shadow: 5px 5px lightgray;
width:400px;
}
td{
padding:10px;
}
</style>
<body>
<form method="get" action="course">
<table>
<tr><td colspan=2 align=center>성별 <input type=radio name=gender value=male>남성
<input type=radio name=gender value=female>여성</td></tr>
<tr><td colspan=2 align=center>도시 <input type=radio name=city value=cheonan>천안
<input type=radio name=city value=suwon>수원
<input type=radio name=city value=seoul>서울</td></tr>
<tr><td colspan=2 align=center>기간 <input type="date" name=date value=기간>~
<input type="date" name=date1 value=기간1></td></tr>
<tr><td colspan=2 align=center>수업과정
<table style=margin-top:auto>
<tr><td align=center>
<input type=checkbox name=lesson value=java>자바
<input type=checkbox name=lesson value=js>JS
<input type=checkbox name=lesson value=HTML/CSS>HTML/CSS
</td></tr>
<tr><td align=center>
<input type=checkbox name=lesson value=DB>DB
<input type=checkbox name=lesson value=Spring>Spring
<input type=checkbox name=lesson value=R>R언어
</td></tr>
<tr><td align=center>
<input type=checkbox name=lesson value=Arduino>아두이노
<input type=checkbox name=lesson value=ML>ML
<input type=checkbox name=lesson value=DL>DL
</td></tr>
</table>
</td></tr>
<tr><td colspan=2 align=center>
<button type=submit>전송</button>
<button type=reset>지우기</button></td></tr>
</table>
</form>
</body>
</html>
course
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<style>
table{
margin-left: auto;
margin-right: auto;
margin-top:300px;
background-color:rgb(248, 226, 198);
border: 5px solid rgb(248, 226, 198);
border-radius: 10px;
box-shadow: 5px 5px lightgray;
width:400px;
}
td{
padding:10px;
align:center;
}
button{
background-color:rgba(0, 0, 0, 0);
color:rgb(175, 131, 131);
border: 1px solid rgb(175, 131, 131);
border-radius: 5px;
}
button:hover{
color: white;
background-color: rgb(175, 131, 131);
}
</style>
<body>
<table>
<tr><td colspan=2 align=center>성별 : ${gender }</td></tr>
<tr><td colspan=2 align=center>도시 : ${city }</td></tr>
<tr><td colspan=2 align=center>기간 : ${date}~${date1}</td></tr>
<tr><td colspan=2 align=center>수업과정 :
<c:forEach var="lesson1" items="${lesson}">
${lesson1},
</c:forEach></td></tr>
<tr><td colspan=2 align=center><button id=btn >확인</button></td></tr>
</table>
</body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document)
.on('click','#btn',function(){
location.href='/home';
})
</script>
</html>
mycontroller
package com.human.springboot;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import jakarta.servlet.http.HttpServletRequest;
@Controller
public class MyController {
@GetMapping("/home")
public String home() {
return "home";
}
@GetMapping("/course")
public String course(HttpServletRequest req, Model model) {
String gender=req.getParameter("gender");
String city=req.getParameter("city");
String date=req.getParameter("date");
String date1=req.getParameter("date1");
String[] lesson=req.getParameterValues("lesson");
System.out.println(gender);
System.out.println(city);
System.out.println(date);
System.out.println(date1);
for(int i=0;i<lesson.length;i++) {
System.out.println(lesson[i]);
}
model.addAttribute("gender",gender);
model.addAttribute("city",city);
model.addAttribute("date",date);
model.addAttribute("date1",date1);
model.addAttribute("lesson",lesson);
return "course";
}
}
<결과>
/home | /course | |
![]() |
![]() |
![]() |
<코드>
home
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page session="true" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<h1>userid [<%=session.getAttribute("userid") %>]</h1>
<% if(session.getAttribute("userid")==null) {%>
<a href="/login">로그인 |</a><a href="/singin"> 회원가입</a>
<%} else {
out.println(session.getAttribute("userid"));
%>
<a href='/logout'>로그아웃</a>
<%} %>
</body>
</html>
login
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<form method="post" action="/doLogin">
<table>
<tr><td>ID</td><td><input type=text name=loginid></td></tr>
<tr><td>PASSWORD</td><td><input type=password name=passcode></td></tr>
<tr><td colspan=2 align=center>
<input type=submit value='로그인'>
<input type=reset value='비우기'>
</td></tr>
</table>
</form>
</body>
</html>
homecontroller
package com.human.springboot;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@Controller
public class HomeController {
@GetMapping("/home")
public String dohome() {
return "home";
}
@GetMapping("/login")
public String showlogin() {
return "login";
}
@PostMapping("/doLogin")
public String doLogin(HttpServletRequest req) {
HttpSession sinfo = req.getSession();
String loginid = req.getParameter("loginid");
String pwd= req.getParameter("passcode");
if(loginid.equals("yeon")&&pwd.equals("123")) {
sinfo.setAttribute("userid",loginid);
}
return "home";
}
@GetMapping("/signin")
public String dosignin() {
return "signin";
}
}
<결과>
/home | /login | /doLogin |
![]() |
![]() |
![]() |
<코드>
home
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page session="true" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
${logininfo}
</body>
</html>
homecontroller
package com.human.springboot;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@Controller
public class HomeController {
@GetMapping("/home")
public String dohome(HttpServletRequest req,Model model) {
HttpSession sinfo =req.getSession();
if(sinfo.getAttribute("userid")==null) {
model.addAttribute("logininfo",
"<a href='/login'>로그인</a> <a href='/signin'>회원가입</a>");
}else {
model.addAttribute("logininfo",
sinfo.getAttribute("userid")+" <a href='/logout'>로그아웃</a>");
}
return "home";
}
@GetMapping("/login")
public String showlogin() {
return "login";
}
@PostMapping("/doLogin")
public String doLogin(HttpServletRequest req) {
String loginid = req.getParameter("loginid");
String pwd= req.getParameter("passcode");
System.out.println("loginid["+loginid+"] pwd ["+pwd+"]");
HttpSession sinfo=req.getSession();
if(loginid.equals("yeon")&&pwd.equals("123")) {
sinfo.setAttribute("userid",loginid);
}
return "redirect:/home";
}
@GetMapping("/signin")
public String dosignin() {
return "signin";
}
}
<결과>
/home | /login | /doLogin |
![]() |
![]() |
![]() |
만약 잘못된 값을 넣는다면 doLogin 화면이 아니라 그냥 home화면으로 돌아간다.
우우우우 수요일!!!!!!!!!!
2023.03.02 (0) | 2023.03.02 |
---|---|
2023.02.28 (0) | 2023.02.28 |
2023.02.24 (0) | 2023.02.24 |
2023.02.23 (0) | 2023.02.23 |
2023.02.22 (0) | 2023.02.22 |