近日體驗了一下Eclipse
打開某個jsp頁面
<?xml version=
<!DOCTYPE taglib PUBLIC
<taglib>
<tlibversion>
<jspversion>
<shortname>dtree</shortname>
<uri>
<tag>
<name>selectResnodes</name>
<tagclass>myWeb
<bodycontent>empty</bodycontent>
<attribute>
<name>id</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>nodeslist</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
AbstractResAction
package myWeb
import java
import javax
import javax
import org
import org
import org
import org
public abstract class AbstractResAction extends Action {
public final ActionForward execute(ActionMapping actionMapping
ActionForm actionForm
HttpServletResponse httpServletResponse) {
String cmd = (
System
if (cmd == null || cmd
return actionMapping
try {
Method method = this
cmd
ActionForm
HttpServletResponse
// 利用反射機制
return (ActionForward) method
actionMapping
httpServletResponse });
} catch (Exception e) {
e
return actionMapping
}
}
}
TestAction
package myWeb
import java
import javax
import javax
import org
import org
import org
import com
public class QueryNodesAction extends AbstractResAction {
public ActionForward showNodesList(ActionMapping mapping
HttpServletRequest request
ResnodesBO bo = new ResnodesBO();
ArrayList alNodes = bo
request
return mapping
}
}
package myWeb
import java
import java
import javax
import javax
import javax
import org
import myWeb
public class SelectTag extends TagSupport {
//這裡的三個屬性對應TestTag
private String id;
private String scope;
private String nodeslist;
/**
* @throws IOException
*/
public int doStartTag() {
ArrayList list = null;
try {
list = (ArrayList) RequestUtils
scope);
} catch (JspException e
e
}
if (list == null || list
return SKIP_BODY;
JspWriter out = pageContext
try {
if (list != null) {
out
for (int i =
ResnodesVO nodevo = (ResnodesVO) list
out
+ nodevo
// System
}
out
out
}
} catch (IOException e) {
e
}
return EVAL_BODY_INCLUDE;
}
public String getId() {
return id;
}
public void setId(String id) {
this
}
public String getNodeslist() {
return nodeslist;
}
public void setNodeslist(String nodeslist) {
this
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this
}
}
……
<action
……
<action type=
<forward name=
</action>
……
</action
……
<%@ taglib uri=
<body>
……
<slotnode:selectResnodes id=
……
</body>
其中prefix的名字是隨便起的
但是在後面用的時候就要用這個名字
<slotnode:selectResnodes …… 中的selectResnodes和TestTag
另外nodeslist=
request
OK
整理的有點亂
從頁面發起
將查詢得到的數據列表用setAttribute加入request
自定義標簽中取request中的加入的數據列表
由自定義標簽中的標簽java文件完成將數據打印出來的功能(用JspWriter類)
在頁面顯示出來
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28770.html