博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Struts2中javascrpit实现form的提交二
阅读量:6615 次
发布时间:2019-06-24

本文共 2030 字,大约阅读时间需要 6 分钟。

    Struts2剔除了Struts中对于form的应用,而actionStrus2)的action则综合了action,和actionForm的应用。但很多的应用中,都需要对输入进行验证,Struts中是将输入给表单,然后取得表单数据进行验证。虽然Struts2中取消了form的应用,这种方式还可以通过灵活地转化来继续使用。下面是两个例子,原理是相同的。因为博文8万字符限制,两个例子分开写。

例二
 
<
SCRIPT 
type
=
"text/javascript"
>
       
function 
addsave()
       
{
       var 
name = document.getElementById(
'subject'
).value.trim();
       
//  var depName = document.getElementById('depName').value.trim();
           
if
(name.length==0)
           
{
               
alert(
'
讲话主题不能为空或者为空格!
'
)
               
return false
;
           
}
           if
(name.length!=0)
           
{
               if 
(name.length<6||name.length>30)
               
{
                  
alert(
'
讲话主题的长度在
6
30
之间!
'
)
                  
return false
;
               
}
           }
           var 
url=
"<c:out value='${cpath}'/>/information/speakaddSaveAction.action"
            document.Form.action=url;
            document.Form.method=
"post"
;
            document.Form.enctype=
"multipart/form-data"
            
document.Form.submit();
       
}
       function 
back()
       
{
           var 
url=
"<c:out value='${cpath}'/>/information/speaklistAction.action"
            document.Form.action=url;
            document.Form.method=
"post"
;
            document.Form.submit();
       
}
    
</
SCRIPT
>
      
...
 
<
form 
name
=
"Form" 
method
=
"post" 
enctype
=
"multipart/form-data"
>
           
<
table 
width
=
"95%" 
border
=
"0" 
align
=
"center" 
cellpadding
=
"4"
              
class
=
"resultTable" 
cellspacing
=
"1"
>
              
<
tr 
class
=
"resultHead"
>
                  
<
td 
width
=
"25%" 
class
=
"leftText"
>
                     
讲话主题
                  
</
td
>
                  
<
td 
width
=
"25%" 
class
=
"lowest"
>
                     
<
s:textfield 
id 
=
"subject" 
name
=
"speak.subject" 
theme
=
"simple" 
/>
                  
</
td
>
                 
...
 
              
</
tr
>
           
</
table
>
           
</
form
>
           
<
table 
width
=
"95%" 
border
=
"0" 
align
=
"center"
>
              
<
tr
>
                  
<
td 
width
=
"80%"
></
td
>
                  
<
td 
width
=
"10%" 
align
=
"right"
>
                     
<
input 
name
=
"button" 
type
=
"button" 
class
=
"buttonOn"
                         
onmouseover
=
"makevisible(this,0)"
                         
onmouseout
=
"makevisible(this,1)" 
onclick
=
"addsave()" 
value
=
"
保存
"
                         
style
=
"cursor: hand;"
>
                  
</
td
>
                  
<
td 
width
=
"10%" 
align
=
"right"
>
                     
<
input 
name
=
"button" 
type
=
"button" 
class
=
"buttonOn"
                         
onmouseover
=
"makevisible(this,0)"
                         
onmouseout
=
"makevisible(this,1)" 
onclick
=
"back()" 
value
=
"
返回
"
                         
style
=
"cursor: hand;"
>
                  
</
td
>
              
</
tr
>
           
</
table
>
         
 
     本文转自 gaochaojs 51CTO博客,原文链接:http://blog.51cto.com/jncumter/167461,如需转载请自行联系原作者
你可能感兴趣的文章
nginx 查看 并发连接数
查看>>
javascript 运算符 技巧
查看>>
详解Oracle RAC入门和提高
查看>>
vim快捷键使用
查看>>
Linux帮助使用方法
查看>>
学习第一周
查看>>
Linux解决用户密码过期但不用修改密码的方法
查看>>
ORA-00245: control file backup operation failed
查看>>
快速掌握Redis——第二招:安装
查看>>
使用jekyll搭建自己的博客系统
查看>>
从Jetty、Tomcat和Mina中提炼NIO构架网络服务器的经典模式(一)
查看>>
Windows 10之 隐藏“此电脑”窗口的6个额外文件夹
查看>>
struct2源码解读(10)之执行action请求前篇
查看>>
Linux下的进程江湖
查看>>
15.1异常处理
查看>>
nginx和lua的协程
查看>>
HAProxy负载均衡web服务
查看>>
chkconfig命令
查看>>
mysql修改替换某个字段的某些值
查看>>
初学者学习Linux之NFS
查看>>