要生成的xml样式,
<first name="PRODUCTS" url="/wisdom/first.do?operate=selectOneandTwo">
<second name="Mobile Accesssories" url="products.html"/>
<second name="Computeramp;Peripherrals" url="products.html"/>
<second name="Digital Product" url="products.html"/>
</first>
second name都是从数据库查出来的,另外url路径包括id
<first name="PRODUCTS" url="/wisdom/first.do?operate=selectOneandTwo">
<second name="Mobile Accesssories" url="products.html"/>
<second name="Computeramp;Peripherrals" url="products.html"/>
<second name="Digital Product" url="products.html"/>
</first>
second name都是从数据库查出来的,另外url路径包括id
if(null!=list){
StringBuffer str=new StringBuffer();
str.append("<?xml version='1.0' encoding='utf-8'?><menu>");
str.append("<first name="HOME" url="index.jsp"></first> ");
str.append("<first name="ABOUT US" url="jsp/about.jsp">");
for (int i = 0; i <list.size(); i++) {
Model model=(Model)list.get(0);
str.append("<second name=\""+model.getNmae()+"\" url=\""model.getUrl()+"\" />");
}
str.append("<first name="CONTACT US" url="/wisdom/jsp/contact.jsp">
</first> ");
str.append("</menu>");
response.setContentType("text/xml;charset=utf-8");
try {
response.getWriter().print(str.toString());
response.flushBuffer();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
可以写个简单的javabean来获得