JSP

[JSP] Response

SangRok Jung 2022. 7. 12. 10:35
반응형

 

 

 

 

 

 

 

 

 

 

 

 

 

Response.


 

 

 

 

 

 

 

 

 

 

 

ResponseMain.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>ResponseMain</title>
</head>
<body>
<h2>로그인</h2>
<%
String loginError = request.getParameter("loginError");
if (loginError != null)
	out.print("로그인 실패");
%>

<form action="ResponseLogin.jsp" method="post">
	아이디:<input type="text" name="user_id"><br>
	패스워드:<input type="text" name="user_pwd"><br>
	<input type="submit" value="로그인">
</form>

<form action="ResponseHeader.jsp" method="get">
날짜:<input type="text" name="date" value="2022-07-11"><br>
숫자:<input type="text" name="int" value="123"><br>
문자:<input type="text" name="str" value="이순신"><br>
	<input type="submit" value="Response 헤더 정보 설정">
</form>

</body>
</html>

 

 

 

 

 

 

 

 

 

ResponseLogin.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Response Login</title>
</head>
<body>
<%
String id = request.getParameter("user_id");
String pwd = request.getParameter("user_pwd");

if (id.equalsIgnoreCase("jsh") && pwd.equalsIgnoreCase("1234"))
{
	//로그인성공.
	response.sendRedirect("ResponseWelcome.jsp");
	
}
else
{
	request.getRequestDispatcher("ResponseMain.jsp?loginError=1").forward(request, response);
}

%>
</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

ResponseHeader.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Collection" %>
<%
SimpleDateFormat s = new SimpleDateFormat("yyyy-mm-dd");

long add_date = s.parse(request.getParameter("date")).getTime();
int add_int	= Integer.parseInt(request.getParameter("int"));
String add_str = request.getParameter("str");

response.addDateHeader("goodday", add_date);
response.addIntHeader("goodNumber", add_int);
response.addHeader("goodman", "세종대왕");
response.addHeader("goodman", add_str);

%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>ResponseHeader</title>
</head>
<body>
<ul>
<%
Collection<String> headerNames = response.getHeaderNames();
for (String headerName : headerNames)
{
	String value = response.getHeader(headerName);
%>
	<li><%= headerName %> : <%= value %> </li>
<% 
}
%>
</ul>
</body>
</html>

 

 

 

 

 

 

 

 

 

 

ResponseWelcome.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome</title>
</head>
<body>
<h1>WELCOME 로그인성공</h1>
</body>
</html>
반응형

'JSP' 카테고리의 다른 글

[JSP] Application  (0) 2022.07.15
[JSP] 내장객체, DTO & JavaBeans  (0) 2022.07.13
[JSP] Request  (0) 2022.07.13
[JSP] out.  (0) 2022.07.12
[JSP] Scriptlet  (0) 2022.07.08