HTML:js
//查询二级节点 function getSonNote(noteId){ //alert('test...'); url="<%=request.getContextPath()%>/HomepageInitServlet?noteId="+noteId+"&flag=1"; sendServer(); return stateString; } function sendServer() { if (window.ActiveXObject){ req = new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ req = new XMLHttpRequest(); } req.open("POST",url,false); req.onreadystatechange = getResponseText; req.send(null); } //ajax通用返回文本 function getResponseText(){ if (req.readyState == 4){ if (req.status == 200){ stateString = req.responseTEXT; } } }
JAVA:servlet
public class HomepageInitServlet extends HttpServlet implements Servlet {
private static final String HOME_PAGEID_EN ="homepage_en";
private static final String HOME_PAGEID_CN ="homepage_cn";
public void init() throws ServletException {}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String resultValue = null ;
int flag = Integer.parseInt(req.getParameter("flag"));
if(flag==1){
Map parameterMap = new HashMap();
String id = req.getParameter("noteId");
try {
IPageDelegate ip=new IPageDelegate();
List opList = ip.getNoteRelationByID(id);
StringBuffer sb=new StringBuffer();
if(null!=opList){
sb.append("<SPAN id=\"checkbox").append(id).append("\">");
for (int i = 0; i < opList.size(); i++) {
PageVO pvo = new PageVO();
pvo = (PageVO) opList.get(i);
String nodeid=pvo.getTypeid();
String treenode=pvo.getTreenode();
String nodename=pvo.getTypename();
if(i==0){
sb.append("<input name=\"typeId\" type=\"radio\" class=\"noBorder\" value=\"").append(treenode).append("\" checked>");
}else{
sb.append("<input name=\"typeId\" type=\"radio\" class=\"noBorder\" value=\"").append(treenode).append("\">");
}
sb.append(nodename).append(" ");
}
sb.append("</SPAN>");
resp.getWriter().write(sb.toString());
}else{
sb.append("<SPAN id=\"checkbox").append(id).append("\">");
sb.append("</SPAN>");
resp.getWriter().write(sb.toString());
}
} catch (ApplicationException e) {
e.printStackTrace();
}
}
}
}