form in struts

王朝other·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

one form in struts should take attention the following:

first, you should have an bean extends org.apache.struts.action.ActionForm,(how to

write this bean you can refrence http://jakarta.apache.org/struts/) here,

we assume the name of the bean is test.UserForm;

second, you should declare the form name in the nest of tag <action-mappings> and

</action-mappings>

for example

<action-mappings>

<action path="/regist" type="net.jspcn.guestbook.LeaveWordAction"

name="leavewordform" scope="request" input="/guestbook/index.jsp" />

<action path="/overview" forward="/guestbook/hello.jsp" />

<action path="/failed" forward="/guestbook/wuwu.jsp" />

<action path="/display" type="net.jspcn.guestbook.Display"

name="userf" scope="request" input="/guestbook/index.jsp" />

</action-mappings>

third, you should specify the type of the form name in the nest of tag <form-beans> and

</form-beans>

for example

<form-beans>

<form-bean name="leavewordform" type="net.jspcn.guestbook.LeaveWordForm">

</form-bean>

</form-beans>

you must take care whether the form name is same in <ation> and <form-bean>,struts request

consistency

fourth,in the .jsp(view part) file, if you use struts tag ,the form action should be

assigned with the path property in the <action> tag

for example

<html:form action="regist.cool" focus="name"

onsubmit="return validateLeavewordform(this);">

fifth,if u wanna focus the cursor in the specified text field ,you .jsp file syntax should

like this

<html:form action="regist.cool" focus="name"

here ,name is the text field name

sixth, if u wanna validate the input with javascript,you .jsp file syntax should like this

onsubmit="return validateLeavewordform(this);"

form name leavewordform,captalize the first word,so it's Leavewordform

then with the prefix validate and suffix (this);

not only this u need to call the javascript validate

this following code is also need

<html:javascript formName="leavewordform" dynamicJavascript="true"

staticJavascript="false"/>

formName is the form name in <form-bean> tag

it also need validator-rules.xml and validation.xml file support

use can reference reference

http://www.jspcn.net/more_news.jsp?type_id=3&board_id=25&board_name=Struts

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航