简单asp.net跨域提交表单详细做法

作者:袖梨 2022-06-25

主要应用就是注册信息太多,以多个页面进行逐步注册操作,大概的原理就是一个actionform对应多个action

 

1,建立一个actionform,有3个域,分别是name,password,email,不用添加jsp教程

 

2.建立一个jsp,名字叫register1.jsp,代码如下

 

view source

flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">

print?

1

<html:form action="/register1.do" method="post">

2

    username:<html:text property="username"/>

3

    <html:errors property="username" />

4

    password:<html:text property="password"/>

5

    <html:errors property="password" />

6

    <input type="hidden" name="page" value="1"/>

7

    <html:submit/>

 

 

3.建立另外一个jsp,名字叫register2.jsp,代码如下

 

<html:form action="/register1.do" method="post">
username:
<html:text property="username"/>
<html:errors property="username" />
password:
<html:text property="password"/>
<html:errors property="password" />
<input type="hidden" name="page" value="1"/>
<html:submit/>

 

 

4.建立2个action,分别是/register1和/register2,如下图所示

 

 

5.编辑actionform的validate方法写入针对表单域的验证代码

 

public actionerrors validate(actionmapping mapping,
https教程ervletrequest request) {
actionerrors errors
=new
actionerrors();
if (request.getparameter("page").equals("1"
)) {
if ("".equals(request.getparameter("username"
))) {
errors.add(
"username",new actionmessage("usernamenull"
));
}
if ("".equals(request.getparameter("password"
))) {
errors.add(
"password", new actionmessage("passwordnull"
));
}
}
if (request.getparameter("page").equals("2"
)) {
if ("".equals(request.getparameter("email"
))) {
errors.add(
"email", new actionmessage("emailnull"
));
}
}
return
errors;
}

 

 

6.编辑资源文件

 

7.编辑register1action代码,主要是跳到输入email的页面,代码如下

 

personalform personalform = (personalform) form;// todo auto-generated method stub
system.out.println(personalform.getusername());
system.out.println(personalform.getpassword());
return mapping.findforward("step2");

 

8.编辑register2action代码,主要是输出用户名,密码,邮箱地址,完成注册

 

personalform personalform = (personalform) form;// todo auto-generated method stub
system.out.println(personalform.getusername());
system.out.println(personalform.getpassword());
system.out.println(personalform.getemail());
return null;

9.增加一个actionforward

 

 

10.最后就是测试,经过测试,完成功能实现

相关文章

精彩推荐