- src/main/java => java
- src/main/webapp/lesson01 => html
http://localhost/lesson01/ex03.html?user_id=yjkim2&name=김유정&age=27
- 쿼리스트링: key-value 정보를 서버한테 넘겨줌 여러개 가능 사이에 & 붙여줌
- 앞에 있는 key를 request parameter 라고 부른다(쿼리스트링의 key)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단 링크</title>
</head>
<body>
<h1>구구단</h1>
<a href="/lesson01/quiz05?number=2">2단</a><br>
<a href="/lesson01/quiz05?number=3">3단</a><br>
<a href="/lesson01/quiz05?number=4">4단</a><br>
<a href="/lesson01/quiz05?number=5">5단</a><br>
<a href="/lesson01/quiz05?number=6">6단</a><br>
<a href="/lesson01/quiz05?number=7">7단</a><br>
<a href="/lesson01/quiz05?number=8">8단</a><br>
<a href="/lesson01/quiz05?number=9">9단</a><br>
</body>
</html>
package lesson01;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/lesson01/quiz05")
public class GetMethodQuiz05 extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
int number = Integer.valueOf(request.getParameter("number"));
PrintWriter out = response.getWriter();
out.println("<html><head><title>구구단 결과</title></head><body><ul>");
for (int i = 1; i <= 9; i++) {
out.println("<li>" + number + " X " + i + " = " + (number * i) + "</li>");
}
out.print("</ul></body></html>");
}
}