开发者

JSP menu design advice

I'm looking to create a horizontal menu in a jsp page - the menu items vary by user but stay consistent over every page in the site for that user apart from the appearance of the active tab. See开发者_运维技巧ms a simple enough problem at first (the appearance is modified using css) but I can't decide where to construct the menu.

Menu code:

<ul>
    <li><a href="url1">item1</a></li>
    <li id="active"><a href="url2">item2</a></li>
</ul>`

As I see it there are 3 choices of when to retrieve menu items:

  1. Upon receipt of HTTP Request to any controller for the first time store two arrays in the session - [url1, url2] and [item1, item2]. Then make the all the jsp pages form this into the above code. The jsp would have to know it's url to make against the [url1, url2] array in order to insert the active id.
  2. Create the above html separately in each controller. Since a controller knows it's own url, it's simple to add the active id.
  3. Create above html without any active id, store the html in the session and make either the jsp pages/controllers modify the html string.

None of these seem particularly appetising.

Does anyone have any advice on this?


Since a JSP is where all the HTML belongs, I'd go for option 1, but then with a List<MenuItem> instead of two loose arrays. You can find JSP's own URL by ${pageContext.request.requestURI}. The JSTL functions library should be helpful in determining whether the URL matches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜