实现不同访问级别的用户
我需要根据用户的访问级别在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个主观问题。就我个人而言,如果页面之间的差异非常小,我会避免选择#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.