我在 welcome.scala.html 页面中编写了注销代码,但在该页面中出现错误我该如何为其编写代码

i have wriiten a logout code in welcome.scala.html page but getting errors in that page how can i write the code for it

localhost sbt

不能使用返回 play.api.mvc.ActionBuilder[play.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

您的路由文件似乎有一个小错误:

改变这个: GET /logout controllers.HomeController.index 进入 GET /logout controllers.HomeController.logout

它应该可以正常工作。