메뉴 건너뛰기

2017.09.12 02:48

request, response

조회 수 3220 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

request

웹브라우저를 통해 서버에 어떤 정보를 요청하는 것.

요청 정보는 request객체가 관리한다.


request 객체 관련 메서드

getContextPath() : 웹어플리케이션의 컨텍스트 패스를 얻는다.

getMethod() : get방식과 post방식을 구분한다.

getSession() : 세션 객체를 얻는다.

getProtocol() : 해당 프로토콜을 얻는다.

getRequestURL() : 요청 URL를 얻는다.

getRequestURI() : 요청 URI를 얻는다.

getQueryString() : 쿼리스트링을 얻는다.


request.obj

  1. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  2.     pageEncoding="EUC-KR"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10.  
  11.     <%
  12.         out.println("서버 : " + request.getServerName() + "<br />");
  13.         out.println("포트 번호 : " + request.getServerPort() + "<br />");
  14.         out.println("요청 방식 : " + request.getMethod() + "<br />");
  15.         out.println("프로토콜 : " + request.getProtocol() + "<br />");
  16.         out.println("URL : " + request.getRequestURL() + "<br />");
  17.         out.println("URI : " + request.getRequestURI() + "<br />");
  18.     %>
  19.  
  20. </body>
  21. </html>



parameter 메서드

Jsp페이지를 제작하는 목적이 데이터 값을 전송하기 위한 목적.


getParameter(String name) : name에 해당하는 파라미터 값을 구한다.

getParameterNames() : 모든 파라미터 이름을 구한다.

getParameterValues(String name) : name에 해당하는 파라미터값들을 구한다.



form.html

  1. <!DOCTYPE html>
  2. <meta charset="EUC-KR">
  3. <title>Insert title here</title>
  4. </head>
  5.     <form action="requestparam.jsp" method="post">
  6.         이름 : <input type="text" name="name" size="10"><br/>
  7.         아이디 : <input type="text" name="id" size="10"><br/>
  8.         비밀번호 : <input type="password" name="pw" size="10"><br/>
  9.         취미 : <input type="checkbox" name="hobby" value="read">독서
  10.         <input type="checkbox" name="hobby" value="cook">요리
  11.         <input type="checkbox" name="hobby" value="run">조깅
  12.         <input type="checkbox" name="hobby" value="swim">수영
  13.         <input type="checkbox" name="hobby" value="sleep">취침<br/>
  14.         전공 : <input type="radio" name="major" value="kor">국어
  15.         <input type="radio" name="major" value="eng" checked="checked">영어
  16.         <input type="radio" name="major" value="mat" >수학
  17.         <input type="radio" name="major" value="des" >디자인<br/>
  18.         <select name="protocol">
  19.             <option value="http(80)">http</option>
  20.             <option value="ftp(20,21)" selected="selected">ftp</option>
  21.             <option value="smtp(25)">smtp</option>
  22.             <option value="pop(110)">pop</option>
  23.         </select><br/>
  24.         <input type="submit" value="전송">
  25.         <input type="reset" value="초기화">
  26.     </form>
  27. </body>
  28. </html>


requestparam.jsp

  1. <%@page import="java.util.Arrays"%>
  2. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  3.    pageEncoding="EUC-KR"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  6. <title>Insert title here</title>
  7. </head>
  8. <%!
  9.     String nameid, pw, major, protocol;
  10.     String[] hobbys;
  11. %>
  12.  
  13. <%
  14.     request.setCharacterEncoding("EUC-KR");
  15.    
  16.     name = request.getParameter("name");
  17.     id = request.getParameter("id");
  18.     pw = request.getParameter("pw");
  19.     major = request.getParameter("major");
  20.     protocol = request.getParameter("protocol");
  21.     hobbys = request.getParameterValues("hobby");
  22. %>
  23.  
  24. 이름 : <%= name %><br />
  25. 아이디 : <%= id %><br />
  26. 비밀번호 : <%= pw %><br />
  27. 취미 : <%= Arrays.toString(hobbys) %><br />
  28. 전공 : <%= major %><br />
  29. 프로토콜 : <%= protocol %><br />
  30. </body>
  31. </html>





response

웹브라우저의 요청에 응답하는것.

응답(response)의 정보를 가지고 있는 객체를 response객체 라고한다.


response 객체 관련 메서드

getCharacterEncoding() : 응답할때 문자의 인코딩 형태를 구한다.

addCookie(Cookie) : 쿠키를 지정한다.

sendRedirect(URL) : 지정한 URL로 이동한다.


request.html

  1. <!DOCTYPE html>
  2. <meta charset="EUC-KR">
  3. <title>Insert title here</title>
  4. </head>
  5.     <form action="request_send.jsp">
  6.         당신의 나이는 : <input type="text" name="age" size="5">
  7.         <input type="submit" value="전송">
  8.     </form>
  9. </body>
  10. </html>


request_send.jsp

  1. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  2.    pageEncoding="EUC-KR"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  5. <title>Insert title here</title>
  6. </head>
  7.  
  8. <%!
  9.     int age;
  10. %>
  11.  
  12. <%
  13.     String str = request.getParameter("age");
  14.     age = Integer.parseInt(str);
  15.    
  16.     if( age >= 20){
  17.         response.sendRedirect("pass.jsp?age=" + age);
  18.     } else {
  19.         response.sendRedirect("stop.jsp?age=" + age);
  20.     }
  21. %>
  22.  
  23. <%= age %>
  24.  
  25. </body>
  26. </html>


pass.jsp

  1. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  2.    pageEncoding="EUC-KR"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  5. <title>Insert title here</title>
  6. </head>
  7.  
  8. <%!
  9.     int age;
  10. %>
  11.  
  12. <%
  13.     String str = request.getParameter("age");
  14.     age = Integer.parseInt(str);
  15. %>
  16.  
  17. 성인 입니다. 주류구매가 가능 합니다.
  18.  
  19. <a href="request.html">처음으로 이동</a>
  20. </body>
  21. </html>


stop.jsp

  1. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  2.    pageEncoding="EUC-KR"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  5. <title>Insert title here</title>
  6. </head>
  7.  
  8. <%!
  9.     int age;
  10. %>
  11.  
  12. <%
  13.     String str = request.getParameter("age");
  14.     age = Integer.parseInt(str);
  15. %>
  16.  
  17. 미성년자 입니다. 주류구매가 불가능 합니다.
  18.  
  19. <a href="request.html">처음으로 이동</a>
  20. </body>
  21. </html>








 



List of Articles
번호 제목 날짜 조회 수
65 Oracle Database DB연결, table 생성 file 2017.09.11 4262
64 JSP 동작 원리, 내부 객체 file 2017.09.12 3579
63 스크립틀릿(Scriptlet), 선언(declaration), 표현식(expression) file 2017.09.12 3637
62 지시자(Directive) file 2017.09.12 3123
61 주석(comments) file 2017.09.12 3114
» request, response file 2017.09.12 3220
59 JSP 게시판 만들기 - 구현 (이클립스 웹 프로젝트 생성) file 2017.09.12 4874
58 JSP 게시판 만들기 - 구현 (이클립스 웹 프로젝트 생성) file 2017.09.12 13391
57 JSP 게시판 만들기 - 개발표준, 화면설계 file 2017.09.12 6596
56 JSP 게시판 만들기 - 시스템 아키텍처 file 2017.09.12 4781
55 JSP (Java Server Page), Servlet에 대해 file 2017.09.12 6709
54 JSP 게시판 만들기 - 네이밍, 데이터베이스 설계 file 2017.09.12 4956
53 JSP 게시판 만들기 - 구현 (웹 프로젝트와 톰켓 연동, 샘플 페이지 작성) file 2017.09.12 5185
52 JSP 게시판 만들기 - 구현 (디렉토리, 파일, 테이블 생성) file 2017.09.12 7909
51 JSP 게시판 만들기 - 구현 (HTML 코딩) file 2017.09.12 17066
50 JSP 게시판 만들기 - 구현 (MySQL과의 연동) file 2017.09.12 37895
49 JSP 게시판 만들기 - 구현 (Method, Query 기초) file 2017.09.12 30633
48 JSP 게시판 만들기 - 구현 (파라미터, 요청/응답) file 2017.09.12 4798
47 JSP 게시판 만들기 - 구현 (마무리, 테스트) file 2017.09.12 6581
46 JSP 게시판 만들기 - 완료 (소스파일, 의견) 2017.09.12 5502
Board Pagination Prev 1 2 3 4 Next
/ 4

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved