站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题帮忙分析下以下代码(50分)

帮忙分析下以下代码(50分)

摘要: 帮忙分析下以下代码(50分)


package component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import readfromxml.ReadXML;

public class CustomList extends TagSupport{
private List toplist = new ArrayList(); // 自定义列表标题
private String path="";
private String tabClass="";
private String titletrClass="";
private String thClass="";
private String tdimgClass="";
private String tdClass="";
private String width="";
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}


public void setToplist(List toplist) {
this.toplist = toplist;
}
public List getToplist() {
return this.toplist;
}

@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
// TODO Auto-generated method stub
ForEach parent=(ForEach)findAncestorWithClass(this,ForEach.class);
StringBuffer buf = new StringBuffer();
String configpath=path+"config//Basic.xml";
buf.append("<table border='0' cellpadding='0' cellspacing='0' class='"+tabClass+"' width='"+width+"'>/n");

//内容title
buf.append("<tr class='"+titletrClass+"'>");
buf.append("<td width='20'> </td><td class='"+thClass+"'>&nbsp;</td>");
//buf.append("<td bgcolor='#EFFFD9' align='center' width='30' class='fontstyle'>序号</td>");

for(int i=0; ibuf.append("<th class='"+thClass+"' width='");
buf.append("'>");
buf.append(toplist.get(i).get(0));
buf.append("</th>");
}

buf.append("<td class='"+tdClass+"' width='30'> </td></tr>");

/////内容列表
@SuppressWarnings("unused")
List replpics=ReadXML.getNodesAttrValues(configpath,"//root/replace","text");

List currentPrint=(List)parent.getCurrentColl();
/*for(int i=0; ifor(int j=0; j<((List)currentPrint.get(i)).size(); j++){
if(!((List)toplist.get(j)).get(1).equals("0")){
buf.append(" buf.append(((List)((List)currentPrint.get(i)).get(j)).get(1)); //例如:歌曲名的链接
buf.append("' target='_blank'>");
if(((List)((List)currentPrint.get(i)).get(j)).get(0)==null)
buf.append("无");
else if(((List)((List)currentPrint.get(i)).get(j)).get(0).equals("下载")&&downpic!=null)
buf.append("");
else
buf.append(((List)((List)currentPrint.get(i)).get(j)).get(0)); //例如:歌曲名

buf.append("");
}

else
if(((List)((List)currentPrint.get(i)).get(j)).get(0)==null)
buf.append("无");
else if(((List)((List)currentPrint.get(i)).get(j)).get(0).equals("下载")&&downpic!=null)
buf.append("");
else
buf.append(((List)((List)currentPrint.get(i)).get(j)).get(0)); //例如:歌曲名



buf.append("</td>");
}

buf.append("</tr>");
}*/
for(int i=0; i//输出序号
buf.append("<tr><td> </td>");
buf.append("<td width='24' class='"+tdClass+"'>
"+(i+1)+".
</td>");
for(int j=0; j//第i条记录的第j个属性
List recordele=(List)currentPrint.get(i).get(j);
buf.append("<td class='");
for(int t=0;tif(replpics.get(t).get(0).equals(recordele.get(0)))
replace=t;
//插入置换图片,其中图片src=replpics.get(replace).get(1)
if(replace!=-1){
buf.append(tdimgClass+"'>");
//无链接
if(toplist.get(j).get(1).equals("0"))
buf.append("");
else
buf.append("");
}


//输出文字
else{
buf.append(tdClass+"'>");
//没有链接
if(toplist.get(j).get(1).equals("0"))
buf.append(recordele.get(0));
else
buf.append(""+recordele.get(0)+"");
}
buf.append("</td>");
}
buf.append("<td></td></tr>");
}
buf.append("</table>");

try {
pageContext.getOut().print(buf);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return SKIP_BODY;
}

public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return EVAL_PAGE;
}

public void release() {
// TODO Auto-generated method stub

}
public String getTabClass() {
return tabClass;
}
public void setTabClass(String tabClass) {
this.tabClass = tabClass;
}
public String getTdClass() {
return tdClass;
}
public void setTdClass(String tdClass) {
this.tdClass = tdClass;
}
public String getTdimgClass() {
return tdimgClass;
}
public void setTdimgClass(String tdimgClass) {
this.tdimgClass = tdimgClass;
}
public String getThClass() {
return thClass;
}
public void setThClass(String thClass) {
this.thClass = thClass;
}
public String getTitletrClass() {
return titletrClass;
}
public void setTitletrClass(String titletrClass) {
this.titletrClass = titletrClass;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}

}

提示
NameList是个tempList集合
tempLIst有三项: 第一项指定该列显示的名称:
第二项指定该列是不是有连接(1为有连接,0为无连接)
第三项指定该列的宽度

ValueList也是tempList集合
templist有两项
第一项指定该行显示对应的字符串
第二项指定该行对应的连接(如果name List对应的列是1)



up


能看完是不简单的,我没本事看完。
不过,我也说说:
这里写的像是Servlet,但又不是继承HttpServlet,
像JavaBean,但又有JSP页面代码,这是怎么搞的,一个字。“乱”

PS:建议看一个struts精通MVC.


up


你最好只把关键代码写出来,其他的没问题的不要贴了


报什么错误


提出你的问题,帖出错误信息,帖出主要代码,最好多点注释,让大家看起来方便,简洁,明了。


太长了  呵呵


写的自定义标签


友情帮顶,太长了.......


写的一个自定义标签.
在jsp页面输出html代码.
xml定义都没写出来,还有传进去的几个值没有加以说明.



写这么长,没有信心看完它啊。
短一点的话会看看的。



看一下struts
并多了解MVC.
哈哈哈哈


↑返回目录
前一篇: 启动tomcat时log4j的报错,求原因
后一篇: 有谁做过内容管理系统吗?如何做这样一个组件呢?