日期:2014-05-19 浏览次数:20671 次
<s:form action="register" method="post"> <s:textfield name="user.username" label="用户名"/> <s:password name="user.password" label="密码"/> <s:submit value="注册"/> <s:reset value="重填"/> </s:form>
<package name="default" extends="struts-default"> <action name="register" class="action.RegisterAction"> <result name="success">/success.jsp</result> </action>
<bean id="userDao" class="Realized.UserDaoHibernate" /> <bean id="User" class="bean.User"/> <bean id="registerAction" class="action.RegisterAction"> <property name="user" ref="User"/> <property name="userDao" ref="userDao"/> </bean>
package action; import javax.annotation.Resource; import bean.User; import com.opensymphony.xwork2.ActionSupport; import dao.UserDao; public class RegisterAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private UserDao userDao; public UserDao getUserDao() { return userDao; } @Resource public void setUserDao(UserDao userDao) { this.userDao = userDao; } private User user; public User getUser() { return user; } @Resource public void setUser(User user) { this.user = user; } public String execute() throws Exception { userDao.saveUser(user); return SUCCESS; } }