Skip to content

Instantly share code, notes, and snippets.

@sgykfjsm
Created February 25, 2013 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgykfjsm/5030812 to your computer and use it in GitHub Desktop.
Save sgykfjsm/5030812 to your computer and use it in GitHub Desktop.
Scalatraで簡単にGETとPOSTを試す。
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