본문 바로가기

Study/Programming

JSP submit get/post전송

반응형

form1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<!-- Get 방식(링크걸 때 주로 사용 -->
<a href="form_ok1.jsp?test1=1234&test2=가나다&test3=abc">링크가기</a>

<p>
<!-- Get 방식 -->
<form action="form_ok1.jsp" method="get">
<input type="text" name="test1"/>
<input type="text" name="test2"/>
<input type="submit" value="전송하기"/>
</form>

<br><br>

<!-- Post 방식 -->
<form action="form_ok1.jsp" method="post">
<input type="text" name="test1"/>
<input type="text" name="test2"/>
<input type="submit" value="전송하기"/>
</form>

<br><br>

<form action="form_ok1.jsp" method="post">
<input type="text" name="test1" size="42"/><br>
<textarea name="test2" rows="4" cols="40"></textarea><br>

<input type="checkbox" name="fruit1"> 딸기<br>
<input type="checkbox" name="fruit2"> 바나나<br>
<input type="checkbox" name="fruit3"> 수박<br>

<input type="checkbox" name="fruits" values="딸기"> 딸기<br>
<input type="checkbox" name="fruits" values="바나나"> 바나나<br>
<input type="checkbox" name="fruits" values="수박"> 수박<br>
<input type="submit" value="전송하기"/>
</form>

</body>
</html>


form_ok1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    request.setCharacterEncoding("utf-8");
    String test1 = request.getParameter("test1");
    String test2 = request.getParameter("test2");
    String test3 = request.getParameter("test3");
   
    out.println("test1 : " +test1 +"<br>");
    out.println("test1 : " +test2 +"<br>");

    String fruit1 = request.getParameter("fruit1");
    String fruit2 = request.getParameter("fruit2");
    String fruit3 = request.getParameter("fruit3");
   
    out.println("fruit1 : " +fruit1 +"<br>");
    out.println("fruit2 : " +fruit2 +"<br>");
    out.println("fruit3 : " +fruit3 +"<br>");
   
    String[] fruits = request.getParameterValues("fruits");
    for(int i=0; i<fruits.length; i++){
        out.println(fruits[i] + " : ");       
    }
    out.println("<br>");
%>

반응형

'Study > Programming' 카테고리의 다른 글

JSP 달력  (0) 2009.05.28
JSP get/post 값 넘겨주기  (0) 2009.05.28
JSP 서버이름, 클라이언트ip  (0) 2009.05.28
jsp 달력, 구구단  (0) 2009.05.27
JSP DB연동  (0) 2009.05.27