Struts2 接受参数方法
2012-12-06 14:45
183 查看
jsp:
<!-- 属性接受参数 -->
<form action="" name="f" method="post">
账号:<input type="text" name="username"/><br>
密码:<input type="password" name="password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f.action='<%=actionPath %>acceptparameter';document.f.submit()"/>
<hr>
<!-- PO接受参数 -->
<form action="" name="f1" method="post">
账号:<input type="text" name="user.username"/><br>
密码:<input type="password" name="user.password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f1.action='<%=actionPath %>acceptparameter1';document.f1.submit()"/>
<hr>
<!-- DTO接受参数 -->
<form action="" name="f2" method="post">
账号:<input type="text" name="userDTO.username"/><br>
密码:<input type="password" name="userDTO.password"/><br>
确认密码:<input type="password" name="userDTO.confirmingPassword"/><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f2.action='<%=actionPath %>acceptparameter2';document.f2.submit()"/>
<hr>
<!-- ModelDriven接口接受参数 -->
<form action="" name="f3" method="post">
账号:<input type="text" name="user.username"/><br>
密码:<input type="password" name="user.password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f3.action='<%=actionPath %>acceptparameter3';document.f3.submit()"/>
action:
<!-- 属性接受参数 -->
public class Acceptparameter extends ActionSupport{
private String username;
private String password;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+username+"password="+password);
return SUCCESS;
}
}
<!-- PO接受参数 -->
public class Acceptparameter1 extends ActionSupport{
private User user;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+user.getUsername()+"password="+user.getPassword());
return SUCCESS;
}
}
PO:
public class User {
private String username;
private String password;
//get,set方法
}
<!-- DTO接受参数 -->
public class Acceptparameter2 extends ActionSupport{
private UserDTO userDTO;
private User user;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("DTOusername="+userDTO.getUsername()+"DTOpassword="+userDTO.getPassword() +"confirmingPassword="+userDTO.getConfirmingPassword());
User u=new User();
u.setUsername(userDTO.getUsername());
u.setPassword(userDTO.getPassword());
System.out.println("username="+u.getUsername()+"password="+u.getPassword());
return SUCCESS;
}
}
PO:
public class UserDTO {
private String username;
private String password;
private String confirmingPassword;
//get,set方法
}
<!-- ModelDriven接口接受参数 -->
public class Acceptparameter3 extends ActionSupport implements ModelDriven<User>{
private User user =new User();
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+user.getUsername()+"password="+user.getPassword());
return SUCCESS;
}
}
PO:
public class User {
private String username;
private String password;
//get,set方法
}
struts.xml:
<!-- 属性接受参数 -->
<action name="acceptparameter" class="Acceptparameter">
<result>
/Hello.jsp
</result>
</action>
<!-- PO接受参数 -->
<action name="acceptparameter1" class="Acceptparameter1">
<result>
/Hello.jsp
</result>
</action>
<!-- DTO接受参数 -->
<action name="acceptparameter2" class="Acceptparameter2">
<result>
/Hello.jsp
</result>
</action>
<!-- ModelDriven接口接受参数 -->
<action name="acceptparameter3" class="Acceptparameter3">
<result>
/Hello.jsp
</result>
</action>
<!-- 属性接受参数 -->
<form action="" name="f" method="post">
账号:<input type="text" name="username"/><br>
密码:<input type="password" name="password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f.action='<%=actionPath %>acceptparameter';document.f.submit()"/>
<hr>
<!-- PO接受参数 -->
<form action="" name="f1" method="post">
账号:<input type="text" name="user.username"/><br>
密码:<input type="password" name="user.password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f1.action='<%=actionPath %>acceptparameter1';document.f1.submit()"/>
<hr>
<!-- DTO接受参数 -->
<form action="" name="f2" method="post">
账号:<input type="text" name="userDTO.username"/><br>
密码:<input type="password" name="userDTO.password"/><br>
确认密码:<input type="password" name="userDTO.confirmingPassword"/><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f2.action='<%=actionPath %>acceptparameter2';document.f2.submit()"/>
<hr>
<!-- ModelDriven接口接受参数 -->
<form action="" name="f3" method="post">
账号:<input type="text" name="user.username"/><br>
密码:<input type="password" name="user.password"/><br><br>
</form>
<input type="button" value="提交" onclick="javacript:document.f3.action='<%=actionPath %>acceptparameter3';document.f3.submit()"/>
action:
<!-- 属性接受参数 -->
public class Acceptparameter extends ActionSupport{
private String username;
private String password;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+username+"password="+password);
return SUCCESS;
}
}
<!-- PO接受参数 -->
public class Acceptparameter1 extends ActionSupport{
private User user;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+user.getUsername()+"password="+user.getPassword());
return SUCCESS;
}
}
PO:
public class User {
private String username;
private String password;
//get,set方法
}
<!-- DTO接受参数 -->
public class Acceptparameter2 extends ActionSupport{
private UserDTO userDTO;
private User user;
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("DTOusername="+userDTO.getUsername()+"DTOpassword="+userDTO.getPassword() +"confirmingPassword="+userDTO.getConfirmingPassword());
User u=new User();
u.setUsername(userDTO.getUsername());
u.setPassword(userDTO.getPassword());
System.out.println("username="+u.getUsername()+"password="+u.getPassword());
return SUCCESS;
}
}
PO:
public class UserDTO {
private String username;
private String password;
private String confirmingPassword;
//get,set方法
}
<!-- ModelDriven接口接受参数 -->
public class Acceptparameter3 extends ActionSupport implements ModelDriven<User>{
private User user =new User();
//get,set方法
@Override
public String execute() throws Exception {
System.out.println("username="+user.getUsername()+"password="+user.getPassword());
return SUCCESS;
}
}
PO:
public class User {
private String username;
private String password;
//get,set方法
}
struts.xml:
<!-- 属性接受参数 -->
<action name="acceptparameter" class="Acceptparameter">
<result>
/Hello.jsp
</result>
</action>
<!-- PO接受参数 -->
<action name="acceptparameter1" class="Acceptparameter1">
<result>
/Hello.jsp
</result>
</action>
<!-- DTO接受参数 -->
<action name="acceptparameter2" class="Acceptparameter2">
<result>
/Hello.jsp
</result>
</action>
<!-- ModelDriven接口接受参数 -->
<action name="acceptparameter3" class="Acceptparameter3">
<result>
/Hello.jsp
</result>
</action>
相关文章推荐
- struts2的常量、动态方法调用、接受请求参数处理、类型转换
- Struts2(四) 接受参数的三种方法
- Struts2大约Action系统培训6大约action的接受三个参数的方法
- Struts2中action接受参数方法
- Struts2接受请求参数三种常用方法
- struts2的action接受参数:可以决定用不用写getter/setter方法(未经过测试)
- struts2的常量、动态方法调用、接受请求参数处理、类型转换 .
- struts2的接受form表单参数的方法
- Struts2中action接受参数的方法,属性:DomainModel、ModelDriver和ActionSupport
- 使用Struts2的模型驱动(ModelDriven)来接受参数发现取不到值---解决方法
- Struts2中action接受参数方法
- Struts2的action接受请求参数的几种方法
- struts2-动态调用方法&接受请求参数
- Struts2的Action接受参数的方法介绍
- struts2 jsp取得action参数的方法
- struts2拦截器 获得请求方法名+获得请求参数
- struts2中action接收参数的方法
- struts2的静态参数封装及3种动态参数封装方法
- Python实现接受任意个数参数的函数方法
- 使用echarts类库,在后台封装option,提供两种使用struts2传递参数到页面的方法