How do I immediately load another page in JSP/Spring?
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 r开发者_运维知识库esult. This saves a click.
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:
if(items.size==1){
//Query items[0] info
return new ModelAndView("itemInfo",model);
}
else{
return new ModelAndView("listOfItems",model);
}
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.
document.location.href = '/path';
精彩评论