在Grails中跟踪多个请求中的变量

时间:2022-10-06 23:38:24

For a webapp written in Grails I would like to keep track of the current users account. In addition the account-name should be displayed as part of the url.

对于用Grails编写的webapp,我想跟踪当前的用户帐户。此外,帐户名称应显示为URL的一部分。

1) Keep the variable in the session 2) Pass the variable via account parameters

1)将变量保留在会话中2)通过帐户参数传递变量

Currently I am experimenting with option 2 which allows me to create URL's like http://app.com/accountname/controller. The drawback is that with every URL I will have to pass the account name along as a variable. This is tedious and error prone.

目前我正在试验选项2,它允许我创建URL,如http://app.com/accountname/controller。缺点是,每个URL我都必须将帐户名称作为变量传递。这很乏味且容易出错。

Is any of the two options preferable? Are there better ways in Grails to achieve this?

两种选择中的任何一种都比较好吗? Grails有更好的方法来实现这一目标吗?

Regards, Jens

2 个解决方案

#1


I have been using a session variable to keep track of the user's account.

我一直在使用会话变量来跟踪用户的帐户。

Ie: session.user = userAccount;.

即:session.user = userAccount;。

You could set this in your login controller.

您可以在登录控制器中设置它。

#2


A better way to keep track of the user is probably to set a cookie. It will be sent to the server with every request & you can easily read it. Why do you need the account name to be part of the URL? I can't think of a good reason to put the current users account in the URL. What happens when someone copy's & paste a link, and someone else follows it? Can you give some more details on what you're trying to do?

跟踪用户的更好方法可能是设置cookie。每次请求都会将其发送到服务器,您可以轻松阅读。为什么您需要帐户名称作为URL的一部分?我想不出将当前用户帐户放入URL的充分理由。当有人复制并粘贴链接,而其他人跟随它时会发生什么?你能提供一些关于你想要做什么的更多细节吗?

#1


I have been using a session variable to keep track of the user's account.

我一直在使用会话变量来跟踪用户的帐户。

Ie: session.user = userAccount;.

即:session.user = userAccount;。

You could set this in your login controller.

您可以在登录控制器中设置它。

#2


A better way to keep track of the user is probably to set a cookie. It will be sent to the server with every request & you can easily read it. Why do you need the account name to be part of the URL? I can't think of a good reason to put the current users account in the URL. What happens when someone copy's & paste a link, and someone else follows it? Can you give some more details on what you're trying to do?

跟踪用户的更好方法可能是设置cookie。每次请求都会将其发送到服务器,您可以轻松阅读。为什么您需要帐户名称作为URL的一部分?我想不出将当前用户帐户放入URL的充分理由。当有人复制并粘贴链接,而其他人跟随它时会发生什么?你能提供一些关于你想要做什么的更多细节吗?