action
来源:互联网 发布:sql server count 慢 编辑:程序博客网 时间:2024/05/21 08:53
package Action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import Bean.Student;
import Service.StudentService;
public class StudentAction extends ActionSupport implements ModelDriven<Student>{
private StudentService service;
//set()接收jsp的form ModelDriven<Student>自动帮我们接收数据
private Student stu=new Student();
//set()接收参数
//封装客户提交的一组产品ID
private int[] checkboxid;
public void setService(StudentService service) {
this.service = service;
}
public String showAll(){
List<Student> list=service.showAll();
ActionContext.getContext().put("list", list);
return "showAll";
}
public String cdAddPage(){
return "enterAdd";
}
public String cdUpdatePage(){
System.out.println(checkboxid[0]);
stu=service.getStudentById(checkboxid[0]); // .put("id",checkboxid[0]);
return "enterUpd";
}
public String add(){
service.add(stu);
return "flush";
}
public String deleteStudents() throws IOException{
for(int i=0;i<checkboxid.length;i++){
System.out.println(checkboxid[i]);
}
HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out= response.getWriter();
if(service.deleteStudentsById(checkboxid)){
out.println("<script>alert('删除数据成功!');location.href='default.jsp';</script>");
}else{
out.println("<script>alert('删除数据失败!');location.href='default.jsp';</script>");
}
out.close();
return null;
}
public String doUpdateStudent() throws IOException{
HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
// System.out.println(stu.toString());
if(service.updateStudent(stu)){
out.println("<script>alert('修改数据成功!');location.href='default.jsp';</script>");
}else{
out.println("<script>alert('修改数据失败!');location.href='default.jsp';</script>");
}
out.close();
return null;
}
@Override
public Student getModel() {
// TODO Auto-generated method stub
return stu;
}
public int[] getCheckboxid() {
return checkboxid;
}
public void setCheckboxid(int[] checkboxid) {
this.checkboxid = checkboxid;
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import Bean.Student;
import Service.StudentService;
public class StudentAction extends ActionSupport implements ModelDriven<Student>{
private StudentService service;
//set()接收jsp的form ModelDriven<Student>自动帮我们接收数据
private Student stu=new Student();
//set()接收参数
//封装客户提交的一组产品ID
private int[] checkboxid;
public void setService(StudentService service) {
this.service = service;
}
public String showAll(){
List<Student> list=service.showAll();
ActionContext.getContext().put("list", list);
return "showAll";
}
public String cdAddPage(){
return "enterAdd";
}
public String cdUpdatePage(){
System.out.println(checkboxid[0]);
stu=service.getStudentById(checkboxid[0]); // .put("id",checkboxid[0]);
return "enterUpd";
}
public String add(){
service.add(stu);
return "flush";
}
public String deleteStudents() throws IOException{
for(int i=0;i<checkboxid.length;i++){
System.out.println(checkboxid[i]);
}
HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out= response.getWriter();
if(service.deleteStudentsById(checkboxid)){
out.println("<script>alert('删除数据成功!');location.href='default.jsp';</script>");
}else{
out.println("<script>alert('删除数据失败!');location.href='default.jsp';</script>");
}
out.close();
return null;
}
public String doUpdateStudent() throws IOException{
HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
// System.out.println(stu.toString());
if(service.updateStudent(stu)){
out.println("<script>alert('修改数据成功!');location.href='default.jsp';</script>");
}else{
out.println("<script>alert('修改数据失败!');location.href='default.jsp';</script>");
}
out.close();
return null;
}
@Override
public Student getModel() {
// TODO Auto-generated method stub
return stu;
}
public int[] getCheckboxid() {
return checkboxid;
}
public void setCheckboxid(int[] checkboxid) {
this.checkboxid = checkboxid;
}
}
0 0
- ACTION
- Action
- action
- action
- action
- *.action
- action
- Action
- ACTION
- action
- Action
- ACTION
- Action
- action
- <action>
- Action
- Action
- Action
- c语言之split实现
- 中文分词算法研究
- 基础-encodeURI
- NSNotificationCenter通知基本用法(一)
- 对象创建,对象方法
- action
- poj3468(A simple Problem with Integers)(线段树成段增减)
- pl/sql 块和结构
- 94. Binary Tree Inorder Traversal
- 【Android】解决在RelativeLayout中使用ImageView, adjustViewBounds 无效
- 团体程序设计天梯赛L2-004 这是二叉搜索树吗?(数据结构)
- Light OJ 1007 Mathematically Hard [欧拉函数+前缀和]【数论】
- Matlab在图片上画个半圆和矩形
- C++中enum的使用