본문 바로가기
교육/Java&Spring

kosta 클라우드 네이티브 애플리케이션 개발 과정 day 29

by Renechoi 2023. 2. 1.

kosta 클라우드 네이티브 애플리케이션 개발 과정 day 29

 

 


쿠키 : 브라우저에 저장 

세션 : 톰캣 같은 서버에 저장 

 

 

jsp의 내부 객체들 

 

대표적인 것 request, response 

그 외 : out, session, application, page, pageContext, 

 

 

 

 

request와 response로 입력받은 객체 처리하기 

 

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"/>
</head>
<body>
<h1>Request Example1</h1>
<form method="post" action="request1.jsp">
 성명 : <input name="name"><br/>
 학번 : <input name="studentNum"><br/>
 성별 : 남자 <input  type="radio" name="gender"  value="man" checked>
          여자 <input type="radio" name="gender" value="woman"><br/>
 전공 : <select name="major">
         <option selected value="국문학과">국문학과</option>
         <option value="영문학과">영문학과</option>
         <option value="수학과">수학과</option>
         <option value="정치학과">정치학과</option>
         <option value="체육학과">체육학과</option>
      </select><br/>
<input type="submit" value="보내기">
</form>
</body>
</html>
<%@ page contentType="text/html;charset=EUC-KR"%>
<%
      String protocol = request.getProtocol();
      String serverName = request.getServerName();
      int serverPort = request.getServerPort();
      String remoteAddr = request.getRemoteAddr();
      String remoteHost = request.getRemoteHost();
      String method = request.getMethod();
      StringBuffer requestURL = request.getRequestURL();
      String requestURI = request.getRequestURI();
      String useBrowser = request.getHeader("User-Agent");
      String fileType = request.getHeader("Accept");
%>
<h1>Request Example2</h1>
프로토콜 : <%=protocol%><p/>
서버의 이름 : <%=serverName%><p/>
서버의 포트 번호 :<%=serverPort%><p/>
사용자 컴퓨터의 주소 : <%=remoteAddr%><p/>
사용자 컴퓨터의 이름 : <%=remoteHost%><p/>
사용 method : <%=method%><p/>
요청 경로(URL) : <%=requestURL%><p/>
요청 경로(URI) : <%=requestURI%><p/>
현재 사용하는 브라우저 : <%=useBrowser%><p/>
브라우저가 지원하는 file의 type : <%=fileType%><p/>

 

 

<%@ page contentType="text/html;charset=EUC-KR"%>
<%
      response.setHeader("Pragma","no-cache");
   if(request.getProtocol().equals("HTTP/1.1")){
      response.setHeader("Cache-Control","no-store");
   }
%>
<h1>Response Example1</h1>
http://localhost/myapp/ch07/response1.jsp가<p/>
http://localhost/myapp/ch07/response1_1.jsp로 변경이 되었습니다.

 

 

 

session.... 

 

<%@ page contentType="text/html;charset=EUC-KR"
         session="true"
%>
<%
     request.setCharacterEncoding("EUC-KR");

     String id = request.getParameter("id");
     String pwd = request.getParameter("pwd");

      session.setAttribute("idKey",id);
     session.setMaxInactiveInterval(60*5);
%>
<h1>Session Example1</h1>
<form method="post" action="session1_1.jsp">
    1.가장 좋아하는 계절은?<br/>
   <input type="radio" name="season" value="봄">봄
   <input type="radio" name="season" value="여름">여름
   <input type="radio" name="season" value="가을">가을
   <input type="radio" name="season" value="겨울">겨울<p/>

   2.가장 좋아하는 과일은?<br/>
   <input type="radio" name="fruit" value="watermelon">수박
   <input type="radio" name="fruit" value="melon">멜론
   <input type="radio" name="fruit" value="apple">사과
   <input type="radio" name="fruit" value="orange">오렌지<p/>
   <input type="submit" value="결과보기">
</form>
<%@ page contentType="text/html;charset=EUC-KR"%>
<%
      request.setCharacterEncoding("EUC-KR");

      String season = request.getParameter("season");
      String fruit = request.getParameter("fruit");
       String id = (String)session.getAttribute("idKey");    
      String sessionId = session.getId();
      int intervalTime = session.getMaxInactiveInterval();
 
      if(id != null){
%>
<h1>Session Example1</h1>
<b><%=id%></b>님이 좋아하시는 계절과 과일은<p/>  
<b><%=season%></b>과 <b><%=fruit%></b> 입니다.<p/>
세션 ID : <%=sessionId%><p>
세션 유지 시간 : <%=intervalTime%>초<p/>
<%
    session.invalidate();
   }else{
         out.println("세션의 시간이 경과를 하였거나 다른 이유로 연결을 할 수가 없습니다.");
    }
%>

 

 

 

 

page 객체 

 

<%@ page info = "JSPStudy.co.kr"
    contentType="text/html;charset=EUC-KR"%>
<% 
       String pageInfo = this.getServletInfo();
%>
<h1>Page Example1</h1>
현재 페이지의 info값 : <%=pageInfo%>

 

 

exception 객체 

 

<%@ page contentType="text/html;charset=EUC-KR"
         errorPage="exception2.jsp"
%>
<%
  int one  = 1;
  int zero = 0;
%>
<h1>Exception Example1</h1>
one / zero = <%=one/zero%><p/>
            

 

isErrorPage 세팅을 true로 한다. 

<%@ page contentType="text/html;charset=UTF-8"
                    isErrorPage="true"
%>
<%
   String message = exception.getMessage();
   String objectMessage = exception.toString();
%>
에러 메세지 : <b><%=message%></b><p/>
에러 실체의 클래스명과 에러 메세지  : <b><%=objectMessage%></b><p/>

 

 


서블릿 

 

JSP 이전에 동적인 웹페이지 컨텐츠를 생성하는 기술로 제공

단점이 많지만 존재 이유 

- JSP에는 없는 서버 측 프로그램의 가능

- 대규모 프로젝트에 사용되는 프레임워크의 기술에 사용 

 

반응형