实现不同访问级别的用户

发布于 2024-12-27 02:57:30 字数 135 浏览 0 评论 0原文

我需要根据用户的访问级别在 JSP 页面中显示内容。此内容略有不同(附加按钮、链接)

我应该做什么?
1.在控制器中处理这个逻辑并转发到不同的页面?
2. 使用表达式语言创建一个页面? (使用 c:if 或 c:when )

I need to show content in JSP page based on user's access level. This content differs slightly (additional buttons, links)

What should I do?
1. process this logic in the controller and forward to different pages?
2. create one page using Expression Language? (use c:if or c:when )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不语却知心 2025-01-03 02:57:31

这是一个主观问题。就我个人而言,如果页面之间的差异非常小,我会避免选择#1,正如您所说的只是一些不同的按钮。选项 #2 将限制重复的代码:您不必制作 2 个非常相似的页面。

缺点是,如果您在视图页面中添加了一些额外的逻辑,则很难维护。

对于像附加链接这样的简单情况,您可以考虑从控制器调用函数来获取用户根据其角色有权访问的链接/按钮列表(假设按钮分组在一起)。这会将逻辑保留在您的控制器/模型中。

This is kind of a subjective question. Personally, I would avoid option #1 if the differences between the pages would be very minor, as you have said just some different buttons. Option #2 will limit duplicated code: you won't have to make 2 very similar pages.

The downside is that it you have put some additional logic in your view page and that is difficult to maintain.

For a simple case like additional links, you may consider calling a function from your controller to get a list of links/buttons the user has access to based on their role (assuming the buttons are grouped together). That would keep the logic in your controller/model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文