Struts動態表單的建立,struts動態表單

來源:互聯網
上載者:User

Struts動態表單的建立,struts動態表單


一.在struts中如何?動態表單的建立(1)第一步:建立一個簡單的註冊頁面:

  <body>    <form action="/DynamicForm/register.do?flag=register" method="post">    u:<input type="text" name="name"/><br/>    p:<input type="password" name="password"/><br/>    <input type="submit" value="註冊使用者" />    </form>  </body>

(2)第二步:在struts-config.xml檔案中配置動態表單:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"><struts-config><form-beans><!-- 動態建立表單 表單是配置出來的  不是定義出來的--><!-- 這裡的type是在  Struts 1.3 Libraries中的struts-core-1.3.8.jar 下的DynaActionForm.class的路徑--><form-bean name="userForm" type="org.apache.struts.action.DynaActionForm"><!-- 這裡的name即是表單中的屬性  --><form-property name="name" type="java.lang.String" /><form-property name="password" type="java.lang.String" /><form-property name="name" type="java.lang.String" /></form-bean></form-beans><global-exceptions /><global-forwards /><action-mappings><action      attribute="userForm"      input="/WEB-INF/register.jsp"      name="userForm"      parameter="flag"      path="/register"      scope="request"      type="com.lc.struts.action.RegisterAction"      cancellable="true" >      <forward name="registerok" path="/WEB-INF/ok.jsp" /></action></action-mappings><message-resources parameter="com.lc.struts.ApplicationResources" /></struts-config>


(3)建立處理商務邏輯的action :RegisterAction過程如下:1.建立Action

package com.lc.struts.action;//導包即可public class RegisterAction extends DispatchAction {public ActionForward register(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {DynaActionForm userForm = (DynaActionForm) form;/* * 從動態表單中取出資料的方法 */String name = userForm.get("name").toString();String password = userForm.get("password").toString();System.out.println(name+""+password+"");return mapping.findForward("registerok"); //成功後返回的頁面}}


(4)struts的視圖如下:






struts 動態表單問題

資源檔這麼寫:
# Resources for parameter 'com.fj.bdl.chain.bean.action.ApplicationResources'
# Project chainstore
# Struts Validator Error Messages
name=<b>name</b>
password=<b>passWord</b>
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.

errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.

JSP頁面顯示錯誤資訊:
<html:errors property="name"/>
<html:errors property="password"/>

資源檔貌似不能設定編碼,我不確定
一般都用 國際化 實現中文輸出資源檔的錯誤資訊, 去瞭解下國際化吧
 
struts動態表單驗證出問題了

Exception creating bean of class

這個應該是因為沒有找到 DynaValidatorFrom 類

看你項目裡,是否添加了Struts的jar 包

感覺應該是這個意思

讓你建立一個類 應該是找不到
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.