Servlet :  JAVA에서 HTML 를 사용하기 위해

 

1. WebServlet 프로젝트 >   javaResources > src > package명 > ServletTest.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
import javax.servlet.*;
import java.io.*;
 
public class ServletTest extends HttpServlet{
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
          response.setContentType("text/html");
          response.setCharacterEncoding("euc-kr");
          Calendar c=Calendar.getInstance();
          int hour=c.get(Calendar.HOUR_OF_DAY);
          int minute=c.get(Calendar.MINUTE);
          int second=c.get(Calendar.SECOND);
          PrintWriter out=response.getWriter();
          out.write("<HTML><HEAD><TITLE>ServletTest</TITLE></HEAD>");
          out.write("<BODY><H1>");
          out.write("현재시각은 ");
          out.write("시 ");
          out.write("분 ");
          out.write("초입니다.캬캬");
          out.write("</H1></BODY></HTML>");
          out.close();
     }
}
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
 

 

2. WebContent > WEB-INF > lib > servlet-api.jar 파일 붙여넣기

 

3. web.xml 열기

 

4. 다음 구문 추가 </web-apps> 위에

<servlet>
	<servlet-name>ServletTest</servlet-name>
	<servlet-class>ServletTest</servlet-class>	
  </servlet>
  <servlet-mapping>
	<servlet-name>ServletTest</servlet-name>
	<url-pattern>/test</url-pattern>	
  </servlet-mapping>

 

5. 실행하기

'Servlet & JSP' 카테고리의 다른 글

JSP 예제_계산기  (0) 2019.06.20
JSP 예제_현재 시간 출력  (0) 2019.06.20
Servlet 구현 환경  (0) 2019.06.20
@Annotation  (0) 2019.06.20
Get/Post 방식  (0) 2019.06.20

+ Recent posts