본문 바로가기

Study/Programming

JSP get/post 값 넘겨주기

<%@ 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");
    if(fruits != null){
        for(int i=0; i<fruits.length; i++){
            out.println(fruits[i] +" : ");
        }
    }
   
    String fruit = request.getParameter("fruit");
    out.println("fruit : " +fruit +"<br>");
   
    String pet = request.getParameter("pet");
    out.println("pet : " +pet +"<br>");
%>


<%@ 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="radio" name="fruit" value="딸기"> 딸기<br>
<input type="radio" name="fruit" value="바나나"> 바나나<br>
<input type="radio" name="fruit" value="수박"> 수박<br>

<br>

<select name="pet">
    <option value="1">강아지</option>
    <option value="2">고양이</option>
    <option value="3">기니피그</option>
    <option value="4">금붕어</option>
</select>
<br>
<input type="submit" value="전송하기"/>
</form>

</body>
</html>

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

JSP Encoder.Decoder  (0) 2009.05.29
JSP 달력  (0) 2009.05.28
JSP submit get/post전송  (0) 2009.05.28
JSP 서버이름, 클라이언트ip  (0) 2009.05.28
jsp 달력, 구구단  (0) 2009.05.27