探索與發現

          研究java技術

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            83 隨筆 :: 0 文章 :: 109 評論 :: 0 Trackbacks
          webwork使用 validation驗證框架,其采用的是攔截器
          看一個例子:
          ??? public String doExecute() throws Exception {
          ???return SUCCESS;
          ??? }
          }
          ------
          在xwork.xml里面添加
          <interceptors>
          ?<interceptor name="validator" class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
          ?</interceptors>
          <action name="validation" class="helloWorld.SimpleAction">
          ???<result name="success" type="dispatcher">
          ????<param name="location">/simple_result.jsp</param>
          ???</result>
          ???<result name="error" type="dispatcher">
          ????<param name="location">/simple.jsp</param>
          ???</result>
          ???<!-- If you don't override execute(), you must do this: -->
          ???<result name="input" type="dispatcher">
          ????<param name="location">/simple.jsp</param>
          ???</result>
          ???<interceptor-ref name="validator" />
          ???<interceptor-ref name="debugStack" />
          ???<interceptor-ref name="defaultStack" />
          ???
          ??</action>
          注意interceptor為多個時與servlet里面的filter一樣按順序依次傳遞,假若失敗就為影響后面的程序運行效果.
          還有兩個jsp頁面
          simple_result.jsp
          <%@ taglib prefix="ww" uri="webwork"%>
          <html>
          ?<head>
          ??<title>WebWork Validation Example</title>
          ?</head>
          ?<body>
          ??<p>
          ???The count is
          ???<ww:property value="count" />
          ??</p>
          ??</form>
          ?</body>
          </html>
          --
          simple.jsp
          <%@ taglib prefix="ui" uri="webwork" %>
          <html>
          <head>
          ??? <title>WebWork Validation Example</title>
          </head>
          <body>
          <form action="validation.action" method="post">
          <table>
          ???? <ui:textfield label="Set the counter" name="count"/>
          ??? <ui:submit value="'Submit'"/>
          </table>
          </form>
          </body>
          </html>
          運行效果如下
          count must be between 0 and 5, current value is 8.

          下面為日期類型的驗證
          <field-validator type="date">
          <param name="min">12/22/2002</param>
          ? <param name="max">12/25/2002</param>
          ? <message>The date must be between 12-22-2002 and 12-25-2002.</message>
          </field-validator>
          </field>
          <field name="foo">
          <field-validator type="int">
          <param name="min">0</param>
          <param name="max">100</param>
          <message key="foo.range">Could not find foo.range!</message>
          </field-validator>
          </field>
          </validators>


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


          網站導航:
           
          主站蜘蛛池模板: 芜湖县| 健康| 历史| 西藏| 洛宁县| 凭祥市| 梅州市| 香港 | 武山县| 达拉特旗| 崇义县| 怀化市| 吴堡县| 甘谷县| 秦皇岛市| 成武县| 鹤峰县| 遂溪县| 柳江县| 长垣县| 夏津县| 金寨县| 辉南县| 镶黄旗| 互助| 云阳县| 徐州市| 沧源| 丹寨县| 朝阳市| 大港区| 祥云县| 句容市| 陆河县| 乳源| 武强县| 于都县| 祁东县| 晴隆县| 高台县| 太谷县|