1、定义baseAction,存放结果码常量,请求、响应、上下文、公用的传值
2、Struts标签的使用
s:iterator
S:action
S:url
S:form
s:textfield
S:select
S:radio
S:param
s:textarea
1、不直接跳页面,跳子控制器,因为路径问题和*。action配置
2、修改页面弹栈的问题,load出的结果作为跟,属性可以直接取值
3、页面样式问题 theme
package com.zking.test.web;
import java.sql.SQLException;
import com.zking.test.dao.ClazzDAO;
import com.zking.test.util.BaseAction;
public class ClazzAction extends BaseAction{
public String execute() {
try {
this.result=new ClazzDAO().list();
} catch (InstantiationException | IllegalAccessException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
package com.zking.test.web;
import java.sql.SQLException;
import com.opensymphony.xwork2.ModelDriven;
import com.zking.test.dao.StudentDAO;
import com.zking.test.entity.Student;
import com.zking.test.util.BaseAction;
import com.zking.test.util.PageBean;
public class StudentAction extends BaseAction implements ModelDriven{
private Student student=new Student();
private StudentDAO studentDao=new StudentDAO();
/**
* 查询方法
* @return
*/
public String list() {
try {
this.result=studentDao.list(student,null);
} catch (InstantiationException | IllegalAccessException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return LIST;
}
/**
* 新增方法
* @return
*/
public String add() {
try {
this.studentDao.add(student);
} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
| SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
public String toadd() {
return ADD;
}
/**
* 修改方法
* @return
*/
public String edit() {
try {
this.studentDao.edit(student);
} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
| SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
public String toedit() {
try {
this.result=this.studentDao.load(student);
} catch (InstantiationException | IllegalAccessException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return EDIT;
}
/**
* 删除方法
* @return
*/
public String delete() {
try {
this.studentDao.del(student);
} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
| SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
@Override
public Student getModel() {
return student;
}
}