struts 自定义标签问题. 我今天尝试使用Struts 自定义标签,可是我不知道数据库里的数据通过什么方式传到标签的实现类里面去的.知道的兄弟能帮一下我吗?不胜感激! 如果有例子就再好不过了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 从pageContext获取数据 pageContext.getRequest().getAttribute(form); 我晕你,你自己定义的标签有属性吗? 这些属性是干嘛的? 不就是为了接收数据用的吗?<bean:write name.... 这种标签,不就是有name属性来接收你从后台得到的数据,然后显示吗?楼主实在写不来自定义标签,那就去看 struts 是如何实现的吧。他是开源的,去看源码 实例http://ll-feng.javaeye.com/blog/394775 db --> 有返回值的方法 ---> 保存在内置对象中 ---》在界面上去就行啦,看你会不会struts标签啦 给你一个我自己写的标签,看看就知道啦package com.ccs.govoa.taglib;import java.io.IOException;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import org.apache.struts.taglib.html.BaseHandlerTag;/** * Copyright (c) 2009 * @Description: 通过一个参数查询对应的值 如:通过seqName获得一个key,functionName获得序列的函数 * functionName : sqlmap中的sql的id, * param:传递的参数值 * @date: Dec 14, 2007 * @verison 1.0 * @modify date **/public class GetKeyTag extends BaseHandlerTag { private String functionName; private String param; private int count = 0; public int getCount() { return count; } public void setCount(int count) { this.count = count; } public int doStartTag() throws JspException { JspWriter writer = pageContext.getOut(); StringBuffer value = new StringBuffer(""); if (null != param && !"".equals(param)) { try { if (count <= 0) { value.append(ParentService.getInstance().queryForObject(functionName, param).toString()); } else { for (int i = 0; i < count; i++) { value.append(ParentService.getInstance().queryForObject(functionName, param).toString()) .append(","); } value.delete(value.length() -1, value.length()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { writer.print(value.toString()); } catch(IOException e) { throw new JspException(e.getMessage()); } return super.doStartTag(); } public String getFunctionName() { return functionName; } public void setFunctionName(String functionName) { this.functionName = functionName; } public String getParam() { return param; } public void setParam(String param) { this.param = param; } } 引用<input type="hidden" id="docId" fieldname="docId" issave="true" value="<key:ccskey functionName="getSeqByName" param="SEQ_DOC_KEY"/>"> 【分享】一次有意思的解决绑定变量问题(where in list问题) 为什么连接不上mysql数据库? 如何快捷在Java中分页,效果如百度的1-n后面为省略号或者有其它分页效果? 关于XML的问题 如何用webwork标签逆序输出list QQ右上角那个天气预报是用的什么技术,怎样实现的? jsp页面显示中文时就成乱码 一个简单的问题!!!!!!!!!! 如何利用Stateless Session Bean来实现查询功能? 设计数据库时这样的情况应该如何处理 碰到问题了,请问like后面如何用select语句?急! tomcat发布出错 不懂
pageContext.getRequest().getAttribute(form);
http://ll-feng.javaeye.com/blog/394775
package com.ccs.govoa.taglib;import java.io.IOException;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import org.apache.struts.taglib.html.BaseHandlerTag;
/**
* Copyright (c) 2009
* @Description: 通过一个参数查询对应的值 如:通过seqName获得一个key,functionName获得序列的函数
* functionName : sqlmap中的sql的id,
* param:传递的参数值
* @date: Dec 14, 2007
* @verison 1.0
* @modify date
**/
public class GetKeyTag extends BaseHandlerTag {
private String functionName;
private String param;
private int count = 0;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int doStartTag() throws JspException {
JspWriter writer = pageContext.getOut();
StringBuffer value = new StringBuffer("");
if (null != param && !"".equals(param)) {
try {
if (count <= 0) {
value.append(ParentService.getInstance().queryForObject(functionName, param).toString());
} else {
for (int i = 0; i < count; i++) {
value.append(ParentService.getInstance().queryForObject(functionName, param).toString())
.append(",");
}
value.delete(value.length() -1, value.length());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try
{
writer.print(value.toString());
}
catch(IOException e)
{
throw new JspException(e.getMessage());
}
return super.doStartTag();
}
public String getFunctionName() {
return functionName;
}
public void setFunctionName(String functionName) {
this.functionName = functionName;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
}
<input type="hidden" id="docId" fieldname="docId" issave="true"
value="<key:ccskey functionName="getSeqByName" param="SEQ_DOC_KEY"/>">