- 浏览: 310635 次
- 性别:
- 来自: 成都
-
文章分类
- 全部博客 (118)
- VS2008 (2)
- JAVA (34)
- AJAX (1)
- C# (1)
- Flex (16)
- FMS (6)
- SQLSERVER (1)
- ORACLE (1)
- Quartz (1)
- struts2 (1)
- java数据结构 (1)
- java设计模式 (3)
- JSF (0)
- web (2)
- jbpm4 (4)
- J2EE (1)
- webservice (2)
- javascript (8)
- spring (3)
- lucene (0)
- linux (9)
- ibatis (1)
- JPA (2)
- 外挂 (0)
- VB (0)
- Hibernate (1)
- OSGI (8)
- EXT (4)
- Maven (1)
- SpringSecurity (0)
- activiti (0)
- 项目开发 (0)
- 项目管理 (7)
- android (0)
- FFMPEG (1)
- C (2)
- eclipse (1)
最新评论
-
默默得守候在你的身边:
给力
java与Delphi写的dll交互 -
默默得守候在你的身边:
java与Delphi写的dll交互 -
fuguitong:
[url][url][url][url][url][url][ ...
doc转swf -
baidu_25402161:
到结束的时候一直 Can't delete processIn ...
一个请假单流程的实现(struts2.1.8+spring2.5+hibernate3集成jbpm4.3) -
lohaoo1:
nice!
java面包屑导航制作
做了个简单的面包屑导航功能,比如页面上大家经常看到的这种导航:
我做成了标签的形式,利用jom4j来解析xml文件:
核心类SiteMapTag:
package org.forever.tag; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; /** * 站点导航标签的实现 * @author Administrator * */ public class SiteMapTag extends TagSupport { private static final long serialVersionUID = -3531938467909884528L; private String currentFilePath; private Element target; @Override public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); currentFilePath = request.getRequestURI().replaceFirst(request.getContextPath(), ""); try { Element root = (Element)pageContext.getServletContext().getAttribute("webSiteMapSet"); if(root==null){ SAXReader reader = new SAXReader(); InputStream inputStream = SiteMapTag.class.getClassLoader().getResourceAsStream("sitemap.xml"); Document document = reader.read(inputStream); root = document.getRootElement(); pageContext.getServletContext().setAttribute("webSiteMapSet", root); } parseParent(root); StringBuffer content = new StringBuffer(""); List<String> titles = new ArrayList<String>(); List<String> hrefs = new ArrayList<String>(); while(target!=null){ Attribute attTitle = target.attribute("title"); if(attTitle!=null){ titles.add(attTitle.getText()); } Attribute attHref = target.attribute("href"); if(attHref!=null){ hrefs.add(attHref.getText()); }else{ hrefs.add(""); } target = target.getParent(); } for (int i = titles.size()-1; i >=0; i--) { String href = hrefs.get(i); if(href.equals("")){ content.append(titles.get(i)+"-->"); }else{ content.append("<a href='"+href+"'>"+titles.get(i)+"</a>-->"); } } if(content.length()>0){ this.pageContext.getOut().println(content.delete(content.length()-6, content.length())); } } catch (Exception e) { e.printStackTrace(); throw new JspException(e); } return super.doStartTag(); } private void parseParent(Element parent){ Iterator<Element> it = parent.elementIterator(); while(it.hasNext()){ Element temp = it.next(); Attribute attr = temp.attribute("path"); if(attr!=null){ if(attr.getText().equals(currentFilePath)){ target = temp; return; } } parseParent(temp); } } }
sitemap.tld文件:
<?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <description>站点导航标签</description> <display-name>myTaglib siteMap</display-name> <tlib-version>1.1</tlib-version> <short-name>tagUtil</short-name> <uri>http://tag.forever.org/jsp/tagutil/sitemap</uri> <tag> <description>面包屑标签</description> <name>siteMap</name> <tag-class>org.forever.tag.SiteMapTag</tag-class> <body-content>empty</body-content> </tag> </taglib>
在项目的src下面添加sitemap.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <!-- 配置文件说明, sitemap根节点,title是页面上显示的内容, href是超链接,path是该请求页面的物理路径 --> <sitemap title="音乐社区" href="index.action"> <node title="用户模块"> <node path="/WEB-INF/pages/user/register_view.jsp" href="user/registerView.action" title="用户注册" /> </node> </sitemap>
要使用的jsp加入标签指令:
<%@taglib uri="http://tag.forever.org/jsp/tagutil/sitemap" prefix="tagUtil" %>
在想放的位置处加上标签:
您所在的位置:<tagUtil:siteMap/>就可以了。
sitemap.jar带源码。用的时候别忘了添加jom4j的支持。
- sitemap.jar (5.3 KB)
- 下载次数: 427
评论
4 楼
lohaoo1
2015-10-30
nice!
3 楼
IT成
2015-07-13
jsp页面中如何调用SiteMapTag类,新手,请指教
2 楼
miaowei
2011-11-19
if(attr.getText().equals(currentFilePath)){
target = temp;
return;
}
请问楼主这个判断是什么意思?
target = temp;
return;
}
请问楼主这个判断是什么意思?
1 楼
miaowei
2011-11-19
不知楼主是否使用过,如上所说将两个jar包添加之后,我只需在工程的src下创建一个xml即可,然后在jsp中加入标签,可是为什么没有显示呢?(也没有报错)
发表评论
-
OSGI学习
2012-03-18 18:01 0http://www.blogjava.net/zhenyu3 ... -
OSGI学习笔记(七)
2012-03-17 23:58 1718SpringDM初步使用(二) 介绍哈官方的第二个例子 ... -
ubuntu10.04下nexus和maven的安装及配置
2012-03-14 16:14 2526前提要有jdk环境,官方下载nexus和maven,解压后创建 ... -
ubuntu10.04下eclipse的安装及配置
2012-03-14 00:01 1334从官方http://www.eclipse.org/downl ... -
Ubuntu10.04下配置java环境变量
2012-03-13 23:28 1083Ubuntu10.04默认安装了OpenJDK,但还是基于Su ... -
eclipse设置保护色
2012-03-16 09:22 9434eclipse操作界面默认颜色为白色。对于我们长期使 ... -
OSGI学习笔记(六)
2012-03-17 15:08 2774SpringDM初步使用(一) 官方地址http:// ... -
OSGI学习笔记(八)
2012-03-19 21:08 2324SpringDM初步使用(三) spring第三个例子 ... -
OSGI学习笔记(五)
2011-07-31 10:32 1601开放服务网关协议 (Open Services Gateway ... -
osgi学习笔记(三)
2011-07-16 22:43 1983OSGI实战书上讲了一个web登陆验证切换功能。表达了osgi ... -
word工具类
2011-03-15 09:19 1461package org.foreverframework ... -
命令模式--撤销恢复
2011-03-14 22:32 5015该例子来自阎宏提供的 ... -
java zip
2011-03-06 15:32 1240import java.io.BufferedInputStr ... -
doc转swf
2010-12-07 22:03 8571将doc转换成swf,然后显示在html页面上。 packa ... -
javamail简单使用
2010-11-15 08:29 2380MailInfo类: //发送邮件的信息类 public ... -
xloadtree的一个改造
2010-09-20 22:58 2586修改了xloadtree的部分源码以适合自己使用。 1.修改 ... -
java与Delphi写的dll交互
2010-09-05 22:27 6197有时候在项目开发的时候难免会和硬件提供的开发包接触,这些开发接 ... -
JAVA与DLL交互
2010-08-27 23:32 1969jna官网地址:https://jna.dev.java.ne ... -
office工具类
2010-07-31 14:17 2322将jcom.dll放入jdk的bin目录下,将jcom.jar ... -
启动多个tomcat
2010-04-22 09:13 1242想启动多个tomcat,只需修改conf/server.xml ...
相关推荐
- 观察竞争对手是如何优化分类页面的,比如是否提供了面包屑导航等。 - 优秀的用户体验设计可以显著提升用户满意度。 #### 四、制定网站优化方案 **1. 数据驱动** - 基于之前收集的数据,为不同关键词选择合适的...
BreadCrumbs.vue.bak组件用于显示面包屑导航,帮助用户了解自己所在页面的位置。此外,文档中还提到了构建和运行脚本(如3-build.bat, run.bat),这些批处理文件用于项目构建和启动运行,是项目部署的关键步骤。 ...
组件“BreadCrumbs”则可能用于提供网站导航的面包屑功能,使用户能够快速了解当前位置和返回。 后端部分,文件名中的“3-build.bat”、“2-run.bat”和“1-install.bat”分别指出了项目的构建、运行和安装脚本,这...
- **要点概述**:网站导航系统应当直观易用,使用纯文本链接而非图片或JavaScript链接,并包含面包屑导航。 - **技术实践**:在部分加入声明;在中设置清晰的文字导航菜单。 #### 法则九:遵循W3C标准 - **要点概述...