😀 formtest2
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action= "formsend2.jsp" method="post">
이름<input type="text" name="name"><br>
성별<input type="radio" name="gender" value = "남자" checked>남자
<input type="radio" name="gender" value = "여자" checked>여자<br>
좋아하는 음식
<input type = "checkbox" name="food" value = "떡볶이" checked>떡볶이
<input type = "checkbox" name="food" value = "김밥">김밥
<input type = "checkbox" name="food" value = "라면">라면
<input type = "checkbox" name="food" value = "제육볶음">제육볶음
<input type = "checkbox" name="food" value = "쫄명">쫄면
<input type = "checkbox" name="food" value = "돈까스" checked>돈까스
<input type = "checkbox" name="food" value = "우동">우동<br>
자기소개 <br>
<textarea rows="5" cols="50" name="area"></textarea>
<br><br>
<input type="submit" value="전송">
<input type="reset" value="취소">
</form>
</body>
</html>
😀 formsend2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
h1{
color : red;
}
table{
border : 2px solid green;
}
td{
width : 200px;
height : 50px;
text-align : center;
}
</style>
</head>
<body>
<h1>JSP : Java Server Page</h1>
<%
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("name");
String userGender = request.getParameter("gender");
String foods[] = request.getParameterValues("food");
String vfood = "";
for(int i = 0; i < foods.length; i++){
vfood += foods[i] + "<br>";
}
String textInfo = request.getParameter("area");
//textInfo에는 엔터기호(\r\n)가 포함되어 있다
textInfo = textInfo.replaceAll("\r", "").replaceAll("\n", "<br>");
%>
<table border ="1">
<tr>
<td>이름</td>
<td><%= userName %></td>
</tr>
<tr>
<td>성별</td>
<td><%= userGender %></td>
</tr>
<tr>
<td>좋아하는 음식</td>
<td><%= vfood %></td>
</tr>
<tr>
<td>자기소개</td>
<td><%= textInfo %></td>
</tr>
</table>
</body>
</html>
😀 참고자료




😀 실행


'웹프로그래밍(HTML, CSS3, JavaScript)' 카테고리의 다른 글
[HTML/jsp] placeholder, 전화번호 (0) | 2022.12.25 |
---|---|
[HTML/jsp] file, select, button, multiple (0) | 2022.12.25 |
[HTML&Script] buttonproc (0) | 2022.12.23 |
[HTML&Script] formtest (0) | 2022.12.23 |
[HTML & Script] videotest (0) | 2022.12.23 |