生成的xml格式如下:
1 <?xml version="1.0" encoding="UTF-8" ?>
2- <ea.net>
3 <object LOGINID="admin" USERNAME="admin" fullcontent="[admin][admin]" />
4 <object LOGINID="test1" USERNAME="test" fullcontent="[test1][test]" />
5 </earnet>
控制层方法如下:
1public void query_xml(ActionMapping mapping, ActionForm form,
2 HttpServletRequest request, HttpServletResponse response) {
3 renderDOM(response,autoSuggestService.getAutoSuggestStr("autosuggesttest",request.getParameter( "username" ).trim(), 7));
4 }
1 /** *//**
2 *使用JDom方式
3 * @param response
4 * @param text
5 */
6 protected void renderDOM(HttpServletResponse response, Document doc) {
7 render(response, doc, "text/xml; charset=UTF-8");
8 }
文章来源于领测软件测试网 https://www.ltesting.net/