Action类中的execute()方法是干什么用的
Action类中的execute()方法是干什么用的
execute()方法 它是Action类中的方法?
------解决方案--------------------package com.mytest.action;
import com.mytest.dao.UserDao;
import com.mytest.bean.User;
public class SaveUserAction {
private User use;
private UserDao userDao;
public User getUse() {
return use;
}
public void setUse(User use) {
this.use = use;
}
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public String execute()throws Exception{
userDao.saveUser(use);
return "success";
}}
就是struts2默认的执行函数!在struts.xml中 配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="save" extends="struts-default">
<action name="saveUserAction" class="com.mytest.action.SaveUserAction">
<result name="success">login.jsp</result>
</action>
</package>
</struts>
excute方法返回字符串,看<result name="success">login.jsp</result>配置,如果还回"success"就回到login.jsp页面
------解决方案--------------------一个控制层,你可以看看源代码,,,,