简体   繁体   English

将json检索的数据持久地包含在站点的多个页面中……最佳实践?

[英]Including json retrieved data persistently across multiple pages in a site… best practice?

On this site each page is made up of multiple .jsp files. 在此站点上,每个页面都由多个.jsp文件组成。 There is a main page that contains the bulk of the page content but then navigation is handled by nav.jsp, top title section is handled by top-section.jsp, footer.jsp, etc. 有一个包含大部分页面内容的主页,但随后导航由nav.jsp处理,顶部标题部分由top-section.jsp,footer.jsp等处理。

The content of the pages is populated by data retrieved via json from a middle ware server. 页面的内容由从中间件服务器通过json检索的数据填充。 For the main pages (ie the section of the page that contains the bulk of the page specific data) data is retrieved by an ajax call that uses the logged in users id to get what it needs. 对于主页(即包含大量特定于页面数据的页面部分),数据是通过ajax调用来检索的,该调用使用已登录的用户ID来获取所需的信息。

My question, how do I include some retrieved data in the, say, top-section.jsp. 我的问题是,如何在top-section.jsp中包含一些检索到的数据。 This page is simply (and I'm using hard coded data here but in reality this data should be specific to the logged in user): 该页面很简单(我在这里使用硬编码数据,但实际上,这些数据应特定于已登录的用户):

<div id="userinfo">Harald Niven | <a href="nivenhelp?id=12345">Help</a></div>

This little bit is included in each page so I would like to grab the name ("Harald Niven" and the help url) once and then use it across every page in the site. 这一点包含在每个页面中,因此我想一次获取名称(“ Harald Niven”和帮助URL),然后在站点的每个页面中使用它。 Assuming that communication with the middle ware is via ajax calls that return json, what would be the best way to do this? 假设与中间件的通信是通过返回json的ajax调用进行的,那么最好的方法是什么?

When I load data for each page it is simple, I have a custom js file for that page that grabs the needed data, however, this top section never changes so it seems wasteful to do an ajax request and parse out the response every time... how can I grab this once and persist it across the entire time the user is logged in? 当我为每个页面加载数据时,这很简单,我为该页面提供了一个自定义js文件,该文件可获取所需的数据,但是,此顶部从未更改,因此每次执行ajax请求并解析出响应似乎很浪费。 .. 我怎样才能抓住它一次并在用户登录的整个过程中坚持下去?

Edit: sessions/cookies are out due to requirements of this app and I cannot write to the database... only read from it in a very restricted manner (any requests by the front end folks for accessing the database require a huge pain in the butt amount of approval and explanation so if I can avoid going this route I want to). 编辑:由于此应用程序的要求,会话/ Cookie已退出,我无法写入数据库...仅以非常受限制的方式从数据库中读取(前端人员访问数据库的任何请求都需要极大的痛苦。大量的批准和解释,因此,如果我可以避免走这条路线,我想这么做。

@rg88 , @ rg88,

You need to implement the session management, ideally in all the websites people use a different database to track the users. 您需要实施会话管理,理想情况下,在所有网站上,人们都使用不同的数据库来跟踪用户。

So you need to store the user login info retrived from json object in a track database along with sessionID. 因此,您需要将从json对象检索的用户登录信息与sessionID一起存储在Track数据库中。

Otherwise if you want to go for simple approach , you can store it in the cookies which is not a good practice. 否则,如果您想采用简单的方法,可以将其存储在cookie中,这不是一个好习惯。

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

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