메뉴 건너뛰기

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 회원가입 2019.01.09 918
64 한줄메모 삽입 & AJAX file 2019.01.09 975
63 한줄메모 목록 리스트 AJAX file 2019.01.09 928
62 페이지 화면 이동방식 file 2019.01.09 893
61 패키지 컴파일 방법 2021.03.25 147
60 패키지 생성 bat문 2021.03.25 117
59 파라미터를 배열 형식으로 받기 2021.03.25 1426
58 태그문자&공백문자&줄바꿈 문자 처리 file 2019.01.09 1027
57 지시자(Directive) file 2017.09.12 3123
56 주석(comments) file 2017.09.12 3114
55 아이디 체크 2019.01.09 895
54 스크립틀릿(Scriptlet), 선언(declaration), 표현식(expression) file 2017.09.12 3637
53 수정 삭제 2019.01.09 1075
52 메모 상세 & EL file 2019.01.09 824
51 로그인 & AJAX 비동기 방식으로 처리&암호화&정규표현식 2019.01.09 1247
50 각종 체크 &우편번호 2019.01.09 958
» request, response file 2017.09.12 3220
48 Oracle Database DB연결, table 생성 file 2017.09.11 4262
47 MYSQL JSP 연동 &리스트 뽑아오기 2019.01.09 4436
46 MYSQL JSP insert 폼에서 servlet으로 값넘기기 2019.01.09 26163
Board Pagination Prev 1 2 3 4 Next
/ 4

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved