サーブレット(1) 〜Get編〜
ダウンロード/* * 作成日: 2005/09/10 */ package jp.itsu.itsumono.hp.helloserv; 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; /** * @author itsu */ public class HelloServlet extends HttpServlet{ /* * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ // ContentTypeを設定 response.setContentType("text/html; charset=UTF-8"); // PrintWriterを取得 PrintWriter out = response.getWriter(); // HTMLを出力 out.println("<html>"); out.println("<head>"); out.println("<title>Hello Servlet!</title>"); out.println("</head>"); out.println("<body>"); out.println("Hello Servlet!"); out.println("<br/>"); out.println("こんにちはサーブレット!"); out.println("</body>"); out.println("</html>"); } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Hello Servlet</display-name> <!-- HelloServlet サーブレット --> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>jp.itsu.itsumono.hp.helloserv.HelloServlet</servlet-class> </servlet> <!-- HelloServlet サーブレットのマッピング --> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping> </web-app>