해당 게시물은 Udemy의 "JSP, Servlets and JDBC for Beginners" 강의를 정리한 내용입니다. 영어를 한국어로 번역하는 과정에서 잘못된 부분이 있을 수 있습니다.
This post summarizes Udemy's "JSP, Servlets and JDBC for Beginners" lecture.
1. HTML form 작성하기
<!--student-form.html-->
<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-response.jsp">
First name: <input type="text" name="firstname"/>
<br/><br/>
Last name: <input type="text" name="lastname"/>
<br/><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
2. JSP로 form data 읽기
<html>
<head><title> Student Confirmation Title </title></head>
<body>
The student is confirmed : ${param.firstname} ${param.lastname}
</body>
</html>


<!--student-dropdown-form.html-->
<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-dropdown-response.jsp">
First name: <input type="text" name="firstname"/>
<br/><br/>
Last name: <input type="text" name="lastname"/>
<br/><br/>
<!-- Drop down list -->
<select name="country">
<option> South Korea </option>
<option> Japan </option>
<option> France </option>
<option> India </option>
<option> United Kingdom </option>
</select>
<br/><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
<html>
<head><title> Student Confirmation Title </title></head>
<body>
The student is confirmed : ${param.firstname} ${param.lastname}
<br/><br/>
The student's country : ${param.country}
</body>
</html>


<!--student-radio-form.html-->
<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-radio-response.jsp">
First name: <input type="text" name="firstname"/>
<br/><br/>
Last name: <input type="text" name="lastname"/>
<br/><br/>
Favorite Programming Language : <br/>
<input type="radio" name="favoriteLanguage" value="Java">Java
<input type="radio" name="favoriteLanguage" value="Python">Python
<input type="radio" name="favoriteLanguage" value="C"> C
<br/><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
<html>
<head><title> Student Confirmation Title </title></head>
<body>
The student is confirmed : ${param.firstname} ${param.lastname}
<br/><br/>
The student's favorite programming language: ${param.favoriteLanguage}
</body>
</html>


<!--student-checkbox-form.html-->
<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-checkbox-response.jsp">
First name: <input type="text" name="firstname"/>
<br/><br/>
Last name: <input type="text" name="lastname"/>
<br/><br/>
Favorite Programming Language : <br/>
<input type="checkbox" name="favoriteLanguage" value="Java">Java
<input type="checkbox" name="favoriteLanguage" value="Python">Python
<input type="checkbox" name="favoriteLanguage" value="C"> C
<br/><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
<!-- student-checkbox-response.jsp-->
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head><title> Student Confirmation Title </title></head>
<body>
The student is confirmed : ${param.lastname} ${param.firstname}
<br/><br/>
가장 좋아하는 프로그래밍 언어는 : <br/>
<!-- 가장 좋아하는 언어를 unordered list 태그로 받음 -->
<ul>
<%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset= UTF-8");
String[] langs = request.getParameterValues("favoriteLanguage");
//만약 사용자가 checkbox를 고르지 않는다면, null exception 발생하기에 조건문 추가
if (langs != null) {
for (String tempLang : langs){
out.println("<li>" + tempLang + "</li>");
}
}
%>
</ul>
</body>
</html>


Servers 폴더 ➔ server.xml ➔ Connector 태그에 URIEncoding="euc-kr" 추가