2019.01.31 get형식 & post형식
2019. 1. 31. 16:40ㆍJSP
#1 get형식 & post형식
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <!-- 내용을 전송하기 위해 form을 사용 -> action으로 주소를 입력하여 주소값으로 이동 --> <!-- login.jsp는 상대경로 --> <form action="../loginPro.jsp"> <h1>로그인</h1><br> <!-- * 전송방식 form태그의 method속성으로 지정한다. -get방식(기본) : 전송 데이터가 제한됨, 주소표시줄에 쿼리스트링으로 노출된다. -post방식: 전송 데이터가 무제한임. 주소표시줄에 전송정보가 노출안됨 , 한글처리를 따로 해줘야된다. --> 아이디: <input type="text" name="id"><br><br> 패스워드:<input type="password" name="passwd"><br><br> <input type="submit" value="로그인"> </form> <form action="../loginPro.jsp" method="post"> post 방식: <input type ="text" name="test"> <input type="submit" value="post형식"> </form> </body> </html> | cs |
#2 JSP 영역객체 생명주기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>loginPro</title> </head> <body> <!-- * JSP 영역객체 4개 생명주기 pageContext : 페이지당 1개 request : 클라이언트 요청정보를 가짐 ,요청단위로 1개 session : 클라이언트당 1개 application : 애플리케이션당 1개 --> <% //request String id =request.getParameter("id"); //name의값 , 즉 키의값으로 대응되는 값을 String으로 get String passwd = request.getParameter("passwd"); // 서버 콘솔에 출력 System.out.println(id+" : "+passwd); %> <!-- 브라우저에서 출력 --> 아이디 : <%=id %><br> 패스워드 : <%=passwd %><br> <% // post형식은 setCharacterEncoding("UTF-8");로 한글로 변환하여 사용가능하다. request.setCharacterEncoding("UTF-8"); String str = request.getParameter("test"); %> post 방식: <%=str %> </body> </html> | cs |
'JSP' 카테고리의 다른 글
2019.01.31 Session의 활용 : 로그인페이지 (0) | 2019.01.31 |
---|---|
2019.01.31 Session의 이해 (0) | 2019.01.31 |
2019.01.30 Cookie 만들기(1) (0) | 2019.01.30 |
2019.01.30 JSTL 라이브러리 (0) | 2019.01.30 |
2019.01.29 error : 에러페이지 (0) | 2019.01.29 |