设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > JSP

form in struts

作者:佚名 出处:网络转载 时间:12-05 点击:

内容载入中...
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



收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息