簡単なオウム返し
JSPのうわさを聞いてちょっと試してみたのですが、思っていたよりも簡単でした。ウェブアプリを作るだけならば、RoRよりもJSPの方が手軽だったかもしれません。ただ新しい言語・フレームワークを学びたいので、RoRによる作成は続けようと思います。とりあえずの難関はMVCモデル!
<%@ page contentType="text/html; charset=Windows-31J" %> <% request.setCharacterEncoding("Shift_JIS"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" /> <title>JSP sample</title> </head> <body> <% if (request.getParameter("name") == null || (request.getParameter("name") == "")) { %> <p>はじめまして、あなたのお名前を教えてください。</p> <form method="post" action="test.jsp"> <label for="name">あなたのお名前</label> <input type="text" name="name"> <input type="submit" value="実行"> </form> <% } else { %> <p>こんにちは、<%= request.getParameter("name") %>さん。</p> <% } %> </body> </html>