1
總的noobie問題,我剛剛開始使用Play框架。控制器POST操作響應「未授權」
我添加了一個動作「添加」到我的控制器,當我嘗試訪問它時,我得到了HTTP 403狀態的下一頁。
控制器:
package controllers
import javax.inject._
import play.api._
import play.api.data._
import play.api.data.Forms._
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class HomeController @Inject() extends Controller {
val userForm = Form(
mapping(
"todo" -> text
)(TodoData.apply)(TodoData.unapply)
)
/**
* Create an Action to render an HTML page.
*
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
def index = Action { implicit request =>
Ok(views.html.index())
}
def add = Action { implicit request =>
Ok(views.html.index())
}
}
case class TodoData(todo: String)
路線
# An example controller showing a sample home page
GET / controllers.HomeController.index
POST /add controllers.HomeController.add
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
index.scala.html
@()
@main("Todo App") {
<h1>Welcome to the Todo app</h1>
<form action="/add" method="post">
<label for="todo">TODO:</label>
<input type="text" name="todo" id="todo">
<button type="submit">Add</button>
</form>
}