- TenServlet.java (Dynamic web module version 2.5)
package exam;
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 TenServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public TenServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<h1>1-10까지 출력!!</h1>");
for(int i = 1; i <= 10; i++) {
out.print(i+"<br>");
}
out.close();
}
}
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>exam25</display-name>
<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>
<servlet>
<description></description>
<display-name>TenServlet</display-name>
<servlet-name>TenServlet</servlet-name>
<servlet-class>exam.TenServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TenServlet</servlet-name>
<url-pattern>/ten</url-pattern>
</servlet-mapping>
</web-app>