src/kame.chap02/NowServlet.java
package kame.chap02; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class NowServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ response.setContentType("text/html; charset=euc-kr"); Date now= new Date(); PrintWriter writer = response.getWriter(); writer.println("<html>"); writer.println("<head><title>현재시간</title></head>"); writer.println("<body>"); writer.println("현재시간:"); writer.println(now.toString()); writer.println("</body>"); writer.println("</html>"); writer.close(); } }
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>servletMain</display-name> <servlet> <servlet-name>now</servlet-name> <servlet-class>kame.chap02.NowServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>now</servlet-name> <url-pattern>/now</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
Mapping
<servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>com.base.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping>
package com.base; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ response.setContentType("text/html; charset=utf-8"); try{ PrintWriter out =response.getWriter(); out.println("<html>"); out.println("<head><title>Hello Servlet</title></head>"); out.println("<body>"); out.println("처음 시작하는 Servlet"); out.println("</body>"); out.println("</html>"); out.close(); }catch(Exception e){ e.printStackTrace(); } } }
'JSP > 기본(Oracle)' 카테고리의 다른 글
JSP 메소드 선언 및 호출 (0) | 2012.05.30 |
---|---|
Servlet 생명주기 ,JSP 구성요소 (0) | 2012.05.30 |
POST 방식과 GET 방식 (0) | 2012.05.30 |
Form & Servlet (0) | 2012.05.30 |
JSP 시작 (0) | 2012.05.30 |