想做一个类似csdn这样左边是树右边根据左边局部刷新页面的网站
如题目,最好给我一段代码,只要action和jsp就好
------解决方案--------------------用ajax做和xtree struts做的
这是action
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.form.InfoBean;
import com.yourcompany.service.TreeInfo;
import com.yourcompany.struts.form.TestTreeForm;
/**
* MyEclipse Struts
* Creation date: 08-26-2008
*
* XDoclet definition:
* @struts.action path="/testTree" name="testTreeForm" scope="request" validate="true"
*/
public class TestTreeAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestTreeForm testTreeForm = (TestTreeForm) form;// TODO Auto-generated method stub
TreeInfo objInfo=new TreeInfo();
try
{
PrintWriter out = response.getWriter();
ArrayList array=objInfo.getChild();
request.setCharacterEncoding("GBK");
response.setContentType( "text/xml" );
response.setCharacterEncoding( "GBK" );
StringBuffer sb = new StringBuffer("<?xml version='1.0' encoding='GBK'?><Infos>");
Iterator iter=array.iterator();
while(iter.hasNext())
{
InfoBean objBean=(InfoBean)iter.next();
int parentID = objBean.getParentID();
String childName = objBean.getChildName();
sb.append("<info>");
sb.append("<parentID>" + parentID + "</parentID>");
sb.append("<childName>" + childName + "</childName>");
sb.append("</info>");
}
sb.append("</Infos>");
out.write(sb.toString());
System.out.println(sb.toString());
out.close();
}catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}
这是
jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>XTree</title>
<link type="text/css" rel="stylesheet" href="css/xtree.css">
</head>
<body>
<div style="position: absolute; width: 200px; top: 0px; left: 0px; height: 100%; padding: 5px; overflow: auto;">