JSP 로그인 실습

 

 login.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>
<% 
	String userid = request.getParameter("userid");
	String passwd = request.getParameter("passwd");
	System.out.println("Tomcat Console 출력:" + userid + "\t" + passwd);
	out.print("Browser에 출력:Hello" + userid + "\n");
	
	// Session => HttpSession
	session.setAttribute("id", userid);
	
	// Context ==> ServletContext
	application.setAttribute("id", userid);
	
	// Init Parameter ==> ServletConfig
	String init_param = config.getInitParameter("driver");
%>

아이디:<%= userid %><br>
비번:<%= passwd %><br>

</body>
</html>

 

 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>
<h1>로그인폼 화면</h1>
<form action="login.jsp" method="get">
아이디:<input type="text" name="userid"><br>
비번:<input type="text" name="passwd"><br>
<input type="submit" value="로그인">
</form>
</body>
</html>

 

 출력화면

 

 

 출처

 

강의 실습 + 강의 교재

+ Recent posts