Created
February 25, 2013 15:59
-
-
Save sgykfjsm/5030812 to your computer and use it in GitHub Desktop.
Scalatraで簡単にGETとPOSTを試す。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sgykfjsm.app | |
import org.scalatra._ | |
import scalate.ScalateSupport | |
class MyFirstScalatraServlet extends ScalatraTestStack { | |
get("/") { | |
contentType="text/html" | |
<html> | |
<body> | |
<h1>Scalatra Tutorial</h1> | |
<ul> | |
<li><a href="get">GET TEST</a></li> | |
<li><a href="post">POST TEST</a></li> | |
</ul> | |
</body> | |
</html> | |
} | |
get("/get") { | |
params.get("param") match { | |
case Some(x) => redirect("/get/" + x) | |
case None => | |
contentType="text/html" | |
<html> | |
<body> | |
<h1>Scalatra GET Tutorial</h1> | |
<form action="./get" method="get" > | |
<input type="text" name="param" value="" /> | |
<input type="submit" value="送信" /> | |
</form> | |
<hr/> | |
<a href="/">Beck To Index</a> | |
</body> | |
</html> | |
} | |
} | |
get("/get/:param") { | |
contentType="text/html" | |
<html> | |
<body> | |
<h1>Scalatra GET Tutorial</h1> | |
<p>You submitted: {params("param")}</p> | |
<hr/> | |
<a href="/">Beck To Index</a> | |
</body> | |
</html> | |
} | |
get("/post") { | |
contentType="text/html" | |
<html> | |
<body> | |
<h1>Scalatra POST Tutorial</h1> | |
<form action="./post" method="post" > | |
<input type="text" name="param" value="" /> | |
<input type="submit" value="送信" /> | |
</form> | |
<hr/> | |
<a href="/">Beck To Index</a> | |
</body> | |
</html> | |
} | |
post("/post") { | |
contentType="text/html" | |
<html> | |
<body> | |
<h1>Scalatra POST Tutorial</h1> | |
<p>You submitted: {params("param")}</p> | |
<hr/> | |
<a href="/">Beck To Index</a> | |
</body> | |
</html> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment