【Slim3】Controllerでrequestのパラメータを取得する方法
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JQueryTest</title> </head> <body> <table> <tr> <td> <input id="user" type="text" /> </td> <td> <input id="get" type="button" value="Get" /> </td> </tr> </table> <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(function() { $("#get").click(function(){ $.ajax({ type: "POST", url: "hello", data: "user=" + $("#user").val(), success: function(msg){ alert("Input User: " + msg); } }); return false; }); }); </script> </body> </html>
package tp.controller; import org.slim3.controller.Controller; import org.slim3.controller.Navigation; public class HelloController extends Controller { @Override public Navigation run() throws Exception { String user = this.request.getParameter("user"); response.getWriter().write(user); return null; } }