Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Data전송: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0001 pages from live compare)
 
Line 53: Line 53:
  String list = request.getParameter("name");
  String list = request.getParameter("name");
   
   
  String hobby[] = request.getParameterValues("hobby");
  String hobby[] = request.getParameterValues("hobby");
  String hobby_list = " ";
  String hobby_list = " ";
 
 
Line 59: Line 59:
 
 
  for(int i=0; i < hobby.length; i++) {
  for(int i=0; i < hobby.length; i++) {
  hobby_list = hobby_list + hobby[i] + "  ";
  hobby_list = hobby_list + hobby[i] + "  ";
  }
  }
   
   

Latest revision as of 23:56, 26 March 2026

Explaination

JSP (Request, Response)

클라이언트(form) -> 서버로 전송 html 에서 작성한 텍스트 박스등에 입력된 값을 서버로 전송

전송방식 2가지

  1. Get : 주소에 넣어서 보내는 방식 사용자의 data 가 표시
  2. post  : 주소에 넣지 않고 보내는 방식

// form method="get" or "post" 넣어주면 된다. action="receive.jsp" //

  1. html 이 메인 역활을 하므로 주소창에 파일이름.html 을 설정한다.

Source Code

html File

<html>
<head>

</head>
<body>

<form name="sub"  method="post" action="receive.jsp">
ID : <input type="text" name="id"> <br>
PW : <input type="password" name="pass">
<input type="submit" value="전송">

<select name="name">
<option value="1"> Heo </option>
<option value="2"> Jun </option>
<option value="3"> Su </option>
</select><br>

<input type="checkbox" name="hobby" value="sport">sport
<input type="checkbox" name="hobby" value="music">music
<input type="checkbox" name="hobby" value="movie">movie
<input type="checkbox" name="hobby" value="drama">drama


<br><br>

<input type="radio" name="season" value="spring" checked>spring<br>
<input type="radio" name="season" value="summer">summer<br>
</form>
</body>
</html>

receive.jsp File

<html>
<head>
</head>
<body>
<% String id = request.getParameter("id");
	String pass = request.getParameter("pass");
	String list = request.getParameter("name");

	String hobby[] = request.getParameterValues("hobby");
	String hobby_list = " ";
	
	String season = request.getParameter("season");
	
	for(int i=0; i < hobby.length; i++) {
		hobby_list = hobby_list + hobby[i] + "   ";
	}

	if(list.equals("1")){

%>
Heo <br>
<% 
	} else {
%>
Jun <br>
<% } %>
<%=id%><br>
<%=pass%><br>
<%=list%>
내가 좋아하는 분야는 <%=hobby_list%> <br>
내가 좋아하는 계절은 <%=season%>
</body>
</html>

Thread

JSP