0

localhostsbt私はwelcome.scala.htmlページにログアウトコードをwriitenそれ

がplay.api.mvc.ActionBuilder [プレーを返すメソッドを使用することはできませんのために、私はコードを書くことができますどのようにそのページでエラーが発生しています.api.mvc.Request、play.api.mvc.AnyContent]を実行しながら、私はwelcome.scala.htmlにログアウトボタンをクリックするが、そのコンパイル・エラーを表示した後、バックindex.scala.htmlページに来るようにしようとしていますリクエスト

のハンドラとして。

これはwelcome.scala.htmlページです:

<html> 
    <body> 
welcome to homepage 
     <a href="@routes.HomeController.logout()"> 
     <input type="submit" value="Logout"> 
    </body> 
</html> 

これはindex.scala.htmlページです:

@main("Welcome to Play") { 
} 
<html> 
    <body> 
     username<input type="text" name="uname"> 
     password<input type="password" name="pword"> 
     <a href="@routes.HomeController.welcome()"> 
      <div class="my-button">Submit</div> 
     </a> 
    </body> 
</html> 

これはHomeControllerです:

@Singleton 
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { 
    def index = Action { 
     Ok(views.html.index()) 
    } 
    def welcome = Action 
    { 
     Ok(views.html.welcome()) 
    } 
    def logout = Action 
    { 
     Ok(views.html.index()) 
    } 
} 

これはroutesファイルです:あなたはあなたのルートファイルに小さな誤差を持っているよう

GET /        controllers.HomeController.index 
GET  /welcome       controllers.HomeController.welcome 
GET  /logout       controllers.HomeController.logout 




this is main.scala.html code 


@(title: String)(content: Html) 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
<title>@title</title> 
<link rel="stylesheet"media="screen"href="@routes.Assets.versioned("stylesheets/main.css")"> 
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")"> 
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script> 
</head> 
<body> 
@content 
</body> 
</html> 


got this error after editing the routes page 
Cannot use a method returning play.api.mvc.ActionBuilder[play.api.mvc.Request,play.api.mvc.AnyContent] as a Handler for requests 
+0

何を試しましたか?エラーは何ですか? –

+0

私は2つのテキストボックスと送信ボタンをクリックした後に送信ボタンを押しました。新しいページ(つまりwelcome.scala.htmlページ)を開きます。そのページでは、私はindex.scalaに戻る必要があるログアウトボタンを持っています.htmlページ –

+0

まだ私の問題は解決されませんでした誰も親切にこれに解決策を与えることができますか? –

答えて

1

ようだ:

変更この: GET /logout controllers.HomeController.index GET /logout controllers.HomeController.logout

へとそれだけで動作するはずです。

+0

ルートファイルの更新後にこのエラーが発生しました play.api.mvc.ActionBuilder [play.api.mvc.Request、play.api.mvc.AnyContent]をリクエストのハンドラとして返すメソッドを使用できません –

+0

再生のバージョンは?完全な新しいエラーで質問を編集できますか? – mfirry

+0

私は自分の質問を編集しました。私は2.6.2バージョンのプレイを使用しています –

関連する問題