package com.demo.struts;
import com.demo.struts.dto.UserDTO;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/* action��ҵ���������ߣ���������URI����Ҫ�����������ձ��뽻��action�����?
* ��ôһ��action�������������ݵģ�action������ݵķ�ʽ����Щ��
* 1����action��������������ݡ�
* http://localhost:8080/WebApp/namespace/action!addUser?user_name=struts;
* 2����DomainModel������������������user���������Ժ�DomainModel�ǿ���һ���õġ�
* http://localhost:8080/WebApp/namespace/action!addUser?user.name=struts&user.password=12345;
*
* http://localhost:8080/WebApp/namespace/action!addUser?user.name=struts&user.password=12345&user_name=baoge;
*
* 3�� DTO ���ֽ�����ݵķ��������ҵ�ÿ��ʵ��������ƺ������Զ������ʽ(Hibernate)����ݿ������ݽ������м����
* �ô��ģ��ٸ�����һ���û�Ӧ�õ�����Ӧ�þ�ֻ��name��password��������Client�˻���Ҫ��дconfirm_password������
* confirm_password�в�����Ϊuser��һ�����ԣ���ʱ��Ϊ�˼���action���������Ǿ���Ҫһ��DTO���������������������
* Ȼ���ٸ�ֵ��user.
* http://localhost:8080/Struts2_Path_Demo/test_namespace/test_action!addUser?userDTO.name=Bao
*
* 4��actionʵ��ModelDriven<>����дModelDriven��getModel����
* http://localhost:8080/Struts2_Path_Demo/test_namespace/test_action!addUser?name=Struts2&password=11111;
*
* ע�ⲻ���Ժ��ַ�ʽ��������ݵĶ�Ӧ��action���Ա�����get��set������
*/
public class TestAction extends ActionSupport implements ModelDriven<User>
{
private static final long serialVersionUID = 1L;
String user_name;
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
//�����user Struts2�������new.
UserDTO userDTO;
public UserDTO getUserDTO() {
return userDTO;
}
public void setUserDTO(UserDTO userDTO) {
this.userDTO = userDTO;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("this==");
super.execute();
System.out.println("this=="+ this);
return "first_page";
}
public String addUser()
{
// User user = new User();
// user.setName(userDTO.getName());
// user.setPassword(userDTO.getPassword());
//Hibernate user into the database;
System.out.println("name==" + user.getName());
System.out.println("Password==" + user.getPassword());
return "ADD_OK";
}
User user = new User();
//ModelDriven��getModel����
@Override
public User getModel() {
// TODO Auto-generated method stub
System.out.println("running getModel...");
return user;
}
}
评论0
最新资源