티스토리 뷰
1. 아래를 프로그래밍 하시오.
-JSP 프로젝트 생성
-/hello 로 치고 들어오면 Hello 를 출력하는 HelloWorld.java 서블릿 파일 작성
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package Nov17;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWorld
*/
@WebServlet("/hello")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorld() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// http://localhost:8282/JSP/hello
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
writer.println("<h1>Hello</h1>");
writer.println("</body>");
writer.println("</html>");
writer.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
|
cs |
-/lotto 로 치고 들어오면 로또번호 6개를 출력하는 LottoNum.java 서블릿 파일 작성
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package Nov17;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class LottoNum
*/
@WebServlet("/lotto")
public class LottoNum extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LottoNum() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// http://localhost:8282/JSP/lotto
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
int[] lotto = new int[6];
writer.println("Random Numbers: ");
for (int i = 0; i < lotto.length; i++) {
lotto[i] = (int) (Math.random() * 45 + 1);
for (int j = 0; j < i; j++) {
if (lotto[i] == lotto[j]) {
i--;
break;
}
}
}
writer.println(Arrays.toString(lotto));
writer.println("</body>");
writer.println("</html>");
writer.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
|
cs |
-/gugu3 으로 치고 들어오면 구구단 3단을 출력하는 GuGu3Dan.java 서블릿 파일 작성
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package Nov17;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class GuGu3Dan
*/
@WebServlet("/gugu3")
public class GuGu3Dan extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuGu3Dan() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// http://localhost:8282/JSP/gugu3
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
int n = 3;
for (int i = 1; i < 10; i++) {
writer.println(n + " x " + i + " = " + n * i + "</br>");
}
writer.println("</body>");
writer.println("</html>");
writer.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
|
cs |
-/gugudan 으로 치고 들어오면 구구단(1단~9단)을 출력하는 GuGuDan.java 서블릿 파일 작성
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package Nov17;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class GuGuDan
*/
@WebServlet("/gugudan")
public class GuGuDan extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GuGuDan() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// http://localhost:8282/JSP/gugudan
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
writer.println(i + " x " + j + " = " + (i * j) + "</br>");
}
writer.println("</br>");
}
writer.println("</body>");
writer.println("</html>");
writer.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
|
cs |
.....
2.프로토콜이란 무엇이며, 프로토콜의 종류는?
3.*.jsp 가 컴파일 되는 과정을 설명하시오.
4. 아래를 프로그래밍 하시오.
아래의 주소를 접속시 아래가 웹브라우져에 나타나도록 하시오.
http://localhost:8282/프로젝트명/programmer.jsp
I am a programmer (웹브라우져 출력)
5. HttpServlet에 대하여 설명하시오.
6.web.xml 에 대하여 설명하시오.
'면접준비 > KOSMO 허쌤 숙제' 카테고리의 다른 글
스프링 - Command 객체, 성적 산출, 석탑만들기 (21/12/16) (0) | 2021.12.16 |
---|---|
학습정리-11-18 (0) | 2021.11.18 |
학습정리-11-10 (0) | 2021.11.10 |
학습정리-11-09 (0) | 2021.11.09 |
학습정리-11-08 (0) | 2021.11.08 |
댓글