简体   繁体   English

JSP / Spring MVC应用程序

[英]JSP/Spring MVC application

I am writing a web application using JSP/Spring MVC and would need to customize the UI based on the customer using it. 我正在使用JSP / Spring MVC编写Web应用程序,并且需要根据使用它的客户自定义UI。 I would need to hide/show certain sections of the screen, hide show certain labels and their text boxes and also modify labels based on different customers. 我需要隐藏/显示屏幕的某些部分,隐藏显示某些标签及其文本框,还可以根据不同的客户修改标签。 Currently we are controlling the hide/show in the JSPs by elements and divs based on the logged in customer. 目前,我们根据登录的客户按元素和div控制JSP中的hide / show。 For example: 例如:

if (customer= "A")

show this

else 

hide this

The code gets cluttered and the JSP will get bloated as we add more customers. 随着我们添加更多客户,代码变得混乱,JSP将变得臃肿。 Another alternative I have thought is split a page into sections and control the sections in the same way, but might end up in code repetition accross the JSPs. 我想到的另一个替代方案是将页面拆分为多个部分并以相同的方式控制这些部分,但最终可能会在JSP中进行代码重复。

For example 例如

if (customer = "A")

jsp:include headerA.jsp

else

jsp:include genericheader.jsp

Another alternative would be to write different JSPs and route based on the client. 另一种方法是根据客户端编写不同的JSP和路由。

Is there a better way to handle this kind of situations. 有没有更好的方法来处理这种情况。 Can someone suggest the best practices to implement such a solution? 有人可以建议实施这种解决方案的最佳实践吗?

Thanks. 谢谢。

A UI that chooses what to do for each user can't possibly scale beyond your users A and B. You need a role-based authentication and authorization system. 选择为每个用户执行操作的UI无法扩展到用户A和B之外。您需要基于角色的身份验证和授权系统。

Since you're already using Spring, I'd recommend looking at Spring Security and its role based capabilities. 由于您已经在使用Spring,我建议您查看Spring Security及其基于角色的功能。 There are tags that can help you. 有些标签可以帮助您。

Another way to look at it is that role-based logic like this does not belong in tags. 另一种看待它的方法是像这样的基于角色的逻辑不属于标签。 I'd recommend putting it in controllers and let them assemble pages for you. 我建议把它放在控制器中让他们为你组装页面。

Another possibility is something like SiteMesh, which allows you to create composite views. 另一种可能性是SiteMesh,它允许您创建复合视图。

One more: jQuery was born to manipulate the DOM. 还有一个:jQuery诞生于操纵DOM。 Use it along with CSS. 与CSS一起使用。

First thing it should be based on Role and not based on customer, and each customer will have certain role. 首先应该基于角色而不是基于客户,每个客户都将发挥一定的作用。 It may possible that many customers will have same role and screen access and UI. 许多客户可能会拥有相同的角色和屏幕访问权限以及UI。

Based on role, you can use Spring Secutiry for Authentication and Authorization. 根据角色,您可以使用Spring Secutiry进行身份验证和授权。

If you need to use Layout differently as per customer role, preferably you should use some Layout Manager such as Tiles, SiteMesh etc. 如果您需要根据客户角色使用不同的布局,最好使用一些布局管理器,如Tiles,SiteMesh等。

or use portlets for different login views to different customers 或者使用portlet为不同的客户提供不同的登录视图

You just stated if person A logs in from one store, vs person B logs in from another. 您刚刚声明,如果A人从一个商店登录,而B人从另一个商店登录。 Hate to say it, but that's a role, no matter how you want to spin it, this is related to user authorization. 讨厌说出来,但这是一个角色,无论你想如何旋转它,这都与用户授权有关。

In terms of how you want to implement it, you could do a variety of things, you could intercept the login request and set a session variable which prepends a string to determine the correct view (ie when user a logs in you get customerA, vs customerB, so when rendering the view you'd retrieve the value and render "customerA/index" vs. "customerB/index", etc. 在你想要如何实现它的方面,你可以做各种各样的事情,你可以拦截登录请求并设置一个会话变量,它预先设置一个字符串来确定正确的视图(即当用户登录时你获得customerA,vs customerB,因此在渲染视图时,您将检索该值并呈现“customerA / index”与“customerB / index”等。

You could also determine the person's roles within the controller and render the appropriate view, although this couples your user roles to your controller logic, which wouldn't be recommended in my opinion. 您还可以确定控制器中人员的角色并呈现相应的视图,尽管这会将您的用户角色与控制器逻辑耦合,我认为这是不推荐的。

If this app is going to have a lot of different backends, I'd recommend portlets that way you can write a new backend for each app, rather than bloating your web application with every new store backend. 如果这个应用程序将有很多不同的后端,我建议使用portlet,你可以为每个应用程序编写一个新的后端,而不是每个新的商店后端膨胀你的web应用程序。

Those are just a couple ways, hope this helps. 这些只是几种方式,希望这会有所帮助。

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

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