728x90
반응형
loginForm.jsp
<%@ 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>
<body>
<form method="post" action="testLogin.jsp">
<label for="userid">아이디 : </label>
<input type="text" name="id" id="userid"> <br>
<label for="userpwd">암 호 : </label>
<input type="password" name="pwd" id="userpwd"> <br>
<input type="submit" value="로그인">
</form>
</body>
</html>
testLogin.jsp
<%@page import="java.net.URLEncoder"%>
<%@ 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>
<body>
<%
request.setCharacterEncoding("utf-8");
String id = "root";
String pw = "1234";
if(id.equals(request.getParameter("id")) && pw.equals(request.getParameter("pwd"))){
response.sendRedirect("main.jsp?id=" + URLEncoder.encode(id, "UTF-8"));
}else{
response.sendRedirect("loginForm.jsp");
}
%>
</body>
</html>
loginForm에서 root, 1234를 입력하면 main페이지로 이동하고 아니면 loginForm으로 되돌아감.
main페이지로 이동할 때 id값을 같이 넘김.
main.jsp
<%@ 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>
<body>
<%= request.getParameter("id") %> 님 환영합니다.
</body>
</html>
728x90
반응형
'Spring > JSP' 카테고리의 다른 글
[JSP] JSP에서 다른 페이지로 이동하는 방법 2가지 (0) | 2022.11.15 |
---|---|
[JSP] getParameterValues로 checkbox 값 넘기기 (0) | 2022.11.15 |
[JSP] 회원정보 받기 (0) | 2022.11.14 |
[JSP] JSP의 선언부 (0) | 2022.11.14 |
[JSP] form전송 시 get과 post의 차이 (0) | 2022.11.14 |
댓글