浏览器显示陈旧的 JSP 页面,用户必须手动刷新
我正在用 JSP 开发一个网站。有一个名为“代理机构”的页面,该页面是公开可见的,并显示代理机构的详细信息。但是,当“代理管理员”登录时,会呈现相同的代理页面,其中包含“添加/编辑”链接以修改页面上的数据。
问题是这样的:
用户访问代理页面(此时未登录)
该用户以代理身份登录管理员并再次导航至代理机构页面
在用户手动刷新浏览器之前,代理机构页面不会显示“添加/编辑”链接< /p>
这就是代理页面的链接的样子:
<a href="agency.do?agencyId=<core:out value="${agency.agencyId}" />">
<core:out value="${agency.name}" />
</a>
我一直使用此作为解决方法:
<a href="javascript:void(0)" onclick="javascript:window.location = 'home.do?agencyId=<core:out value="${agency.agencyId}" />&rnd=' + Math.random()">
<core:out value="${agency.name}" />
</a>
我使用 javascript 将随机数附加到 URL。但使用 onclick
而不是 href
感觉不是正确的做法。如果用户想在新选项卡中打开链接怎么办?
我认为这将是一个相当普遍的问题。对此有更好的解决方案吗?
I'm working on a website in JSP. There is a page called Agency which is publicly visible and shows the details of an agency. However, when an "Agency Admin" is logged in, the same Agency page is rendered with Add/Edit links to modify the data on the page.
The problem is this:
A user visits the Agency page (Not logged in at this point)
This user logs in as an Agency Admin and navigates to the agency page again
The agency page doesn't show the Add/Edit links until the user manually refreshes the browser
This is what the link to the Agency page looks like:
<a href="agency.do?agencyId=<core:out value="${agency.agencyId}" />">
<core:out value="${agency.name}" />
</a>
I've been using this as a workaround:
<a href="javascript:void(0)" onclick="javascript:window.location = 'home.do?agencyId=<core:out value="${agency.agencyId}" />&rnd=' + Math.random()">
<core:out value="${agency.name}" />
</a>
I'm appending a random number to the URL using javascript. But using onclick
instead of href
doesn't feel like the right thing to do. What if the user wants to open the link in a new tab?
I thought this would be a fairly common problem. Any better solution to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的浏览器或代理必须缓存该页面。尝试将这些标头添加到缓存的页面的响应中,而不应该是:
关于 JSTL 的用法,我有两点注意:
c
,而不是核心。
URL 应该使用
标签组成。这个标签负责/
开头)并预先添加应用程序的上下文根(/agency.do
变为/myApp/agency.do
)例如:
Your browser or a proxy must cache the page. Try adding those headers to the response of the page which is cached and shouldn't be :
Regarding the JSTL usage, I would have two remarks:
c
, notcore
.A URL is supposed to be composed using the
<c:url>
tag. This tag takes care of/
) and pre-pending the context root of the app (/agency.do
becomes/myApp/agency.do
)For example: