サーブレット(2) 〜Post編〜
ダウンロード/* * 作成日: 2005/09/11 */ 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 HelloPost extends HttpServlet{ /* * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ // リクエストの文字コードを設定 request.setCharacterEncoding("UTF-8"); // ContentTypeを設定 response.setContentType("text/html; charset=UTF-8"); // 名前を取得 String name = request.getParameter("name"); // PrintWriterを取得 PrintWriter out = response.getWriter(); // HTMLを出力 out.println(""); out.println(""); out.println("Hello Post! "); out.println(""); out.println(""); out.print("こんにちは " + name + " さん。"); out.println(""); out.println(""); } }
Hello Servlet HelloServlet jp.itsu.itsumono.hp.helloserv.HelloServlet HelloPost jp.itsu.itsumono.hp.helloserv.HelloPost HelloServlet /HelloServlet HelloPost /HelloPost