<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Denis's Java Library

    The only documentation is the code itself

    自定義標(biāo)簽獲取struts中action的全部路徑(原創(chuàng))

          由于項目里面由需要一個form可以提交多個action(本來可以用 dispatch值來實現(xiàn),后來考慮到要使用validator框架驗證)。后來考慮的方案為使用js來控制form的流向,例如
          
    form.action='/bookstore/checkId.do'

    不過新的問題來了!如何能不用hardcode而拿到我要的action的實際路徑呢?比如我定義的struts-config文件里面的action是 
    path="/checkId"
    但是實際解釋后的path是:
    action='/bookstore/checkId.do'
    前 綴和后面的后綴.do都是根據(jù)你的項目部署的路徑和你在web.xml中配置的mapping的后綴有關(guān)系,如果我把內(nèi)容寫死到j(luò)sp中那以后我要是想把 checkId.do改成checkId.action那就要更改jsp,由于struts本來提供的幾個taglib里面的

    <html:form action="/checkId" >

    綜合了一下決定還是自己寫個taglib來實現(xiàn),其實只需要照著struts 中的 FormTag.java 文件依葫蘆畫瓢就可以了,一下為本人的代碼部分

    StrutsActionCustomTag.java
    package com.denis.framework.common.taglib.strutsActionExt;

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

    import org.apache.struts.taglib.TagUtils;

    public class StrutsActionCustomTag extends TagSupport {

       
    protected String actionName = null;
       
        
    public String getActionName() {
           
    return actionName;
        }


        
    public void setActionName(String actionName) {
           
    this.actionName = actionName;
        }


        
    public int doStartTag() throws JspException {

            StringBuffer results 
    = new StringBuffer();
            HttpServletResponse response 
    =
                (HttpServletResponse) 
    this.pageContext.getResponse();
           
            results.append(response.encodeURL( TagUtils.getInstance().getActionMappingURL( 
    this.actionName , this.pageContext)) );

            TagUtils.getInstance().write(pageContext, results.toString());

           
    return (EVAL_BODY_INCLUDE);
        }


        
    public void release() {
           
    super.release();
           
    this.actionName = null ;

        }

    }


    tld定義部分

    framework-struts.tld
    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <taglib>

    <tlibversion>1.0</tlibversion>
        <jspversion>1.1</jspversion>
        <shortname>framework</shortname>
        <uri>http://www.denisFramework.org/Framework-Tag</uri>
        <tag>
        <name>getActionUrl</name>
        <tagclass>com.denis.framework.common.taglib.strutsActionExt.StrutsActionCustomTag</tagclass>
        <bodycontent>empty</bodycontent>
        <attribute>
             <name>actionName</name>
             <required>true</required>
             <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>

    </taglib>



    ok ! 直接在jsp中如下使用即可取到action的真正路徑

     
    <%@ page language="java"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
    <%@ taglib uri="/WEB-INF/framework-struts.tld" prefix="framework" %>
     
    <html> 
       
    <head>
           
    <title>JSP for loginForm form</title>
       
    </head>
       
    <body>
           
    <framework:getActionUrl actionName="login" />
           
    <html:form action="/login">
                name : 
    <html:text property="name"/><html:errors property="name"/><br/>
                password : 
    <html:password property="password"/><html:errors property="password"/><br/>
               
    <html:submit/><html:cancel/>
           
    </html:form>
       
    </body>
    </html>



    大家要是有更好的解決方法希望能指正!謝謝!

    posted on 2005-11-21 15:52 DenisLing 閱讀(1857) 評論(1)  編輯  收藏

    評論

    # re: 自定義標(biāo)簽獲取struts中action的全部路徑(原創(chuàng)) 2008-03-11 09:53 csch

    直接用lastIndexOf("/")和lastIndexOf(".")獲取最后一個"/"和"."的位置再截取這兩個位置之間的字符串好像也可以吧  回復(fù)  更多評論   


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 成年性生交大片免费看| 亚洲第一网站免费视频| 中文字幕在线亚洲精品| 久久精品夜色国产亚洲av| 亚洲无人区视频大全| 狠狠入ady亚洲精品| 国产性生大片免费观看性| 亚洲黄色免费网站| 亚洲国产精品国产自在在线| 久久精品国产亚洲香蕉| 亚洲精品国产第一综合99久久| 在线视频网址免费播放| 国产日本一线在线观看免费| 亚洲精品国产va在线观看蜜芽| 久久亚洲AV成人无码电影| 国产99久久亚洲综合精品| 99re6在线视频精品免费下载| 日韩a级毛片免费视频| 99久久亚洲综合精品成人网| 亚洲A∨精品一区二区三区下载| 西西人体免费视频| 国产免费观看视频| 亚洲成人福利在线| 中文字幕av免费专区| 免费一级毛片不卡在线播放| 亚洲精品无码久久毛片波多野吉衣| 日本免费精品一区二区三区| 免费h片在线观看网址最新| 亚洲综合色自拍一区| 色偷偷尼玛图亚洲综合| 美女内射毛片在线看免费人动物| 免费成人黄色大片| 亚洲中文字幕无码爆乳app| 免费A级毛片无码专区| 自拍偷自拍亚洲精品情侣| 午夜亚洲国产精品福利| 成人免费视频软件网站| 亚洲综合久久成人69| 99久久婷婷免费国产综合精品| 成在线人永久免费视频播放| 国产精品亚洲精品青青青 |