如何在 JSP/Spring 中立即加载另一个页面?
我对 JSP 不太有经验。我有一个应用程序,它使用 Spring 框架来进行搜索。我在 JSP 页面中显示这些结果。
当搜索仅返回一个项目时,我想立即跳转到显示该项目信息的另一个页面。
这在 JSP/Spring 中可能吗?我见过这样的标签:
<c:redirect url="/somePage.html"/>
That's from another JSP file。我想做的是(这是一段幼稚的代码)...
<c:when test="${cmd.totalResults = 1}">
<c:redirect url="/loadItemInfo.html?id=someId"/>
</c:when>
提前感谢您的建议和帮助!您可以省略有关所涉及参数的任何内容;我能弄清楚这些。我所要求的只是让这一切发生。
- 页面加载。
- Page 看到只有一个结果。
- 页面会转到该结果的页面,这就是用户单击该搜索结果时发生的情况。这样可以节省一次点击。
I'm not very experienced in JSP. I have an application, which uses the Spring framework, that does a search. I show these results in a JSP page.
When the search returns just one item, I want to immediately jump to another page that shows information about that item.
Is this possible in JSP/Spring? I've seen tags like:
<c:redirect url="/somePage.html"/>
That's from another JSP file. What I want to do is (this is a naive bit of code)...
<c:when test="${cmd.totalResults = 1}">
<c:redirect url="/loadItemInfo.html?id=someId"/>
</c:when>
Thanks in advance for your advice and help! You can omit anything regarding the parameters involved; I can figure those out. What I'm asking for is simply making this happen.
- Page loads.
- Page sees that there is only one result.
- Page goes to the page for that result, which is what happens anyway when the user clicks that search result. This saves a click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该检查 Spring 控制器中的项目数逻辑,而不是 jsp 文件中的逻辑。
在你的 Spring 控制器中你可能有这样的东西:
You should check the number of items logic in your Spring controller not in the jsp file.
Inside your Spring controller you may have something like this:
您想显示该页面一段时间并重定向到另一个页面吗?您将无法使用 jsp 标记来执行此操作。你需要 JavaScript。
Do you want to show the page for a while and the redirect to another one? You won't be able to do this with a jsp tag. You need javascript.