让 java 决定 jsp 走向

呵呵,让 java 决定 jsp 走向!
在Action里装饰jsp导航栏,按钮栏!相似的主体不一样的页眉页脚哦。呵呵
(在此以演示按钮栏)
一:总体设计
public ActionForward setUpForInsertOrUpdate(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
.....
//页面中最上面的菜单条

request.setAttribute("tabHtml", this .renderTabControlHtml(InitTabControlXml("Detail", operation,flag)));

//页面中最下面的按钮栏

request.setAttribute("buttonHtml", this.renderButtonHtml(InitBottonControlXml("Detail", operation,flag)));


return mapping.findForward(Constants.SETUPDATE);

}
二:显示按钮栏

/**
* 显示按钮工具条
* @param tabType
* @param operation
* @return
*/


private String InitBottonControlXml(String tabType, String operation,String flag) {
StringBuffer buffer = new StringBuffer("<Param>");

if ("List".equalsIgnoreCase(tabType)) {
buffer.append("<button name ='addDist' οnclick='javascript:add()'>填写请假条</button>");
} else if ("Detail".equalsIgnoreCase(tabType)) {
buffer.append("<button name='updateDist' type='submit'>保存</button>");
if ("update".equals(operation)) {
if("0".equals(flag) || flag==null)
buffer.append("<button name='delDist' οnclick='del()'>删除</button>");
//buffer.append("<button name='print' οnclick='holiday()'>打印</button>");
}
buffer.append("<button name='cancel' οnclick='reback()'>返回</button>");
}
buffer.append("</Param>");
return buffer.toString();
}
三:解析生成的xml
/**
*
* @param buttonXml 传入的button xml字符串
* @return 解析后的 button html串
* @throws Exception
*/

public String renderButtonHtml(String buttonXml) throws Exception{

Reader in= new StringReader(buttonXml);

StringWriter writer = new StringWriter();

try{
ServletContext context = this.getServlet().getServletContext();
String sheetname = context.getRealPath("/commons/button/xml/buttonxsl.xsl");

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(in);

XSLTransformer transformer = new XSLTransformer(sheetname);
Document doc2 = transformer.transform(doc);

XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"));
outp.output(doc2, writer);

}catch(Exception ex){
ex.getMessage();
}
return writer.toString();
}
四("/commons/button/xml/buttonxsl.xsl"),注意了没?
看核心东东:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<span>
<xsl:for-each select="Param/*">
<xsl:choose>
<xsl:when test="name()='button' or name()='a' or name()='checkbox' or name()='select'">
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:when test="name()='group'">
<xsl:for-each select="./*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</span>
</xsl:template>
<xsl:template match="button">
<button>
<xsl:if test="./@name">
<xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
<xsl:attribute name="id">bt_<xsl:value-of select="./@name"/></xsl:attribute>
</xsl:if>
<xsl:attribute name="onclick"><xsl:value-of select="./@onclick"/></xsl:attribute>
<xsl:if test="./@type">
<xsl:attribute name="type"><xsl:value-of select="./@type"/></xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="normalize-space(.)='新增' or normalize-space(.)='新 增'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_new.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='删除' or normalize-space(.)='删 除'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_del.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='保存' or normalize-space(.)='保 存'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_save.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='查询' or normalize-space(.)='查 询'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_search.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='打印' or normalize-space(.)='打 印'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_print.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='确认' or normalize-space(.)='确 认'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_ok.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='关闭' or normalize-space(.)='关 闭'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_close.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='选中' or normalize-space(.)='选 中'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_select.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='提交' or normalize-space(.)='提 交'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_submit.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='审批' or normalize-space(.)='审 批'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_check.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:when test="normalize-space(.)='退审' or normalize-space(.)='退 审'">
<xsl:attribute name="style">background-image:url(commons/button/images/button_false.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:if test="string-length(.) < 3">
<xsl:attribute name="style">background-image:url(commons/button/images/button_null2.gif);width:64px;margin-right:5px;</xsl:attribute>
</xsl:if>
<xsl:if test="string-length(.) > 3">
<xsl:attribute name="style">background-image:url(commons/button/images/button_null1.gif);width:80px;margin-right:5px;</xsl:attribute>
</xsl:if>
<xsl:value-of select="normalize-space(.)"/>
</xsl:otherwise>
</xsl:choose>
</button>
</xsl:template>
<xsl:template match="a">
<font class="abutton">
<xsl:if test="./@name">
<xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
<xsl:attribute name="id">bt_<xsl:value-of select="./@name"/></xsl:attribute>
</xsl:if>
<xsl:attribute name="onclick"><xsl:value-of select="./@onclick"/></xsl:attribute>
<xsl:value-of select="."/>
</font>
</xsl:template>
<xsl:template match="checkbox">
<input type="checkbox">
<xsl:if test="./@name">
<xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
<xsl:attribute name="id">bt_<xsl:value-of select="./@name"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@onclick">
<xsl:attribute name="onclick"><xsl:value-of select="./@onclick"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@checked">
<xsl:attribute name="checked"/>
</xsl:if>
</input>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="select">
<select>
<xsl:if test="./@name">
<xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
<xsl:attribute name="id">bt_<xsl:value-of select="./@name"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@onchange">
<xsl:attribute name="onchange"><xsl:value-of select="./@onchange"/></xsl:attribute>
</xsl:if>
<xsl:for-each select="./option">
<option>
<xsl:if test="./@value">
<xsl:attribute name="value"><xsl:value-of select="./@value"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@selected">
<xsl:attribute name="selected"/>
</xsl:if>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:template>
<xsl:template match="text">
<input type="text" class="seektext">
<xsl:if test="./@name">
<xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute>
<xsl:attribute name="id">bt_<xsl:value-of select="./@name"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@onchange">
<xsl:attribute name="onchange"><xsl:value-of select="./@onchange"/></xsl:attribute>
</xsl:if>
<xsl:if test="./@width">
<xsl:attribute name="style">width:<xsl:value-of select="./@width"/></xsl:attribute>
</xsl:if>
</input>
</xsl:template>
</xsl:stylesheet>
嘿嘿,明白否?
其实jsp导航栏原理一样,想要导航栏的留下大名哦
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值