简体   繁体   English

如何在控制器中获取http请求和查询字符串参数

[英]How to get http request and query string params in the controller

I'm new in the play framework.我是游戏框架的新手。 I'm using play 2.8.x framework and I need to get from the controller session object and params from request.我正在使用 play 2.8.x 框架,我需要从控制器会话对象和请求中获取参数。 But I don't realize how to do that.但我不知道如何做到这一点。 My routes file looks like the following:我的routes文件如下所示:

POST /api/verifyToken/:token        controllers.UserController.verifyToken(token: String, request: Request)

and my controller looks like this:我的控制器看起来像这样:

public class UserController extends Controller {
    public Result verifyToken(String token, Http.Request request) {
        ...
    }
}

and when I try to send a request to the server I had had an error but if I remove token parameter all is working fine.当我尝试向服务器发送请求时,我遇到了一个错误,但是如果我删除了token参数,则一切正常。
How can I pass the request and params to the controller?如何将请求和参数传递给控制器​​?

Your handler is given the Http.Request when it is called:您的处理程序在被调用时会获得Http.Request

java.util.Map<java.lang.String,java.lang.String[]> queryParams = request.queryString();

for the session:会议:

Http.Session session = request.session();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM