Struts2中javascrpit实现form的提交一

      Struts2 剔除了 Struts 中对于 form 的应用,而 action Strus2 )的 action 则综合了 action ,和 actionForm 的应用。但很多的应用中,都需要对输入进行验证, Struts 中是将输入给表单,然后取得表单数据进行验证。虽然 Struts2 中取消了 form 的应用,这种方式还可以通过灵活地转化来继续使用。下面是两个例子,原理是相同的。因为博文8万字符限制,两个例子分开写。
例一
< SCRIPT >
function save() {
    var url= "<c:out value='${cpath}'/>/publication/mydraftupdateAction.action?param=1"
      document.userForm.action=url;
   document.userForm.method= "post" ;
   document.userForm.submit();
}  
function tosubmit() {
 
    var url= "<c:out value='${cpath}'/>/publication/mydraftupdateAction.action?param=0"
    document.userForm.action=url;
   document.userForm.method= "post" ;
   document.userForm.submit();
}
</ SCRIPT >
 
< form name = "userForm" method = "post" >
    < input type = "hidden" name = "publication.id" id = "id" value = "${publication.id}" />
< table width = "95%" align = center cellspacing = "1" class = "contentTable" >
    < tr > < td class = "low" width = "20%" >
        稿件标题
        </ td >
        < td class = "lowest" width = "30%" >
    < input type = "text" name = "publication.title"    id = "title" value = '${publication.title}'>
        </ td >
</ tr >
</ table >
< table width = "95%" border = "0" align = "center" cellpadding = "4"                cellspacing = "1" >
    < tr >
        < td align = "right" >
    < input name = "button" type = "button" class = "button01"
        onmouseover = "makevisible(this,0)"
            nmouseout = "makevisible(this,1)" onclick = "save()" value = " 保存 "
            style = "cursor: hand;" >
    < input name = "button" type = "button" class = "button01"
            onmouseover = "makevisible(this,0)"
            onmouseout = "makevisible(this,1)" onclick = "tosubmit()" value = " 提交 "
            style = "cursor: hand;" >
    < input name = "button" type = "button" class = "button01"
            onmouseover = "makevisible(this,0)"
            onmouseout = "makevisible(this,1)" onclick = "history.back()"
            value = " 返回 " style = "cursor: hand;" >
        </ td >
        </ tr >
    </ table >
总结:先给 form 命名( useform ),点击 " 保存 " 触发 onclick = "save()" save ()方法指定执行的 action rul ,和将整个 useform )提交 submit (( 将整个 useform )提交 submit )不能少,不然会不能提交) 同理 onclick = "tosubmit()" value = " 提交 " )也一样
 
  

你可能感兴趣的:(form,struts2,职场,休闲,javascrpit)