WebContent 아래에 

아래와같은 html 파일을 생성한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name = "join" method="post" action="join">
ID: <input type="text" name="id"> <br>
PWD: <input type="password" name="pwd"> <br>
<input type = "submit">
</form>
</body>
</html>
 
 
 

새로운 servlet을 생성해준다( join )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
 
@WebServlet("/join")
public class join extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    public join() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter Writer = response.getWriter();
        response.setContentType("text/html; charset=UTF-8");
        Writer.println("<html>");
        Writer.println("<head><title>Prameter</title></head>");
        Writer.println("<body>");
        Writer.println("id :"+request.getParameter("id")+"<br>");
        Writer.println("pwd: "+ request.getParameter("pwd"));
        Writer.println("</body></html>");
    }
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

28, 29 : 파라미터 이름으로 값을 추출하는 과정이다 위에 작성한 html에서 id는 name = "id"로 지정했었고, PWD는 name = "pwd"로 지정하였기 때문에 request.getParameter("이름") 으로 추출한다.

이제 접속 해보자

제출 버튼을 누르면

아래와 같이 입력 값들이 추출되어 나온다.

+ Recent posts