package com.action;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//import org.apache.commons.beanutils.BeanUtils;
import net.sf.json.JSONObject;
import org.apache.struts.action.ActionServlet;
import com.bean.Student;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.service.StudentService;
public class StudentAction extends ActionSupport {
private StudentService service;
private String sname;
private String sex;
private String birthday;
private String pid;
private String cname;
private String password;
private String national;
private String susername;
private String origin;
//查询
private String sname1;
private String pid1;
private String sex1;
public String delete()
{
HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();
response.setContentType("text/json;charset=UTF-8");
String cid=request.getParameter("cid");
Student student=(Student)service.findById(Integer.valueOf(cid));
if(student!=null)
{
service.deleteStudent(student);
}
try {
response.getWriter().println("y");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public String fetch()
{
HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();
response.setContentType("text/html;charset=UTF-8");
String cid=request.getParameter("cid");
Student s1=(Student)service.findById(Integer.valueOf(cid));
if(s1!=null)
{
Student s2=new Student();
s2.setBirthday(s1.getBirthday());
s2.setOrigin(s1.getOrigin());
s2.setPassword(s1.getPassword());
s2.setPid(s1.getPid());
s2.setSex(s1.getSex() );
s2.setSid(s1.getSid());
s2.setSname(s1.getSname());
s2.setSnational(s1.getSnational());
s2.setCname(s1.getCname());
s2.setUsername(s1.getUsername());
String _m = JSONObject.fromObject(s2).toString();
try {
response.getWriter().println(_m);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
public String nextGet()
{
HttpServletRequest request=ServletActionContext.getRequest();
int currPage=1;
String curr_page=request.getParameter("currPage");
System.out.println("curr_page: "+curr_page);
int totalPage=countPage();
if(curr_page==null||curr_page.length()<1)
curr_page="1";
currPage=Integer.parseInt(curr_page);
request.setAttribute("currPage", new Integer(currPage));
request.setAttribute("totalPage", new Integer(totalPage));
request.setAttribute("previous", new Integer((currPage>1)?currPage-1:1));
request.setAttribute("next", new Integer((currPage<totalPage)?currPage+1:totalPage));
System.out.println("currPage="+currPage);
System.out.println("totalPage="+totalPage);
System.out.println("previous="+new Integer((currPage>1)?currPage-1:1));
System.out.println("next="+new Integer((currPage<totalPage)?currPage+1:totalPage));
HttpSession session=request.getSession();
String hql=(String)session.getAttribute("hql");
List mlist=service.listStudent(currPage, 10,hql);
request.setAttribute("mlist", mlist);
return this.SUCCESS;
}
public String get(){
HttpServletRequest request=ServletActionContext.getRequest();
StringBuffer hql = new StringBuffer();
hql.append(" From Student ad where 1=1");
if(sname1!=null&&sname1.length()>=1)
{
/*hql.append(" and ad.cname like ?");
params.add("%"+scname+"%");
hql=hql+" and ad.cname like '"+cname+"%'";
*/
hql.append(" and ad.sname like '%"+sname1+"%' ");
}
if(sex1!=null&&sex1.length()>=1)
{
/*
hql.append(" and ad.tname like ?");
params.add("%"+stname+"%");
*/
hql.append(" and ad.sex like '%"+sex1+"%' ");
}
if(pid1!=null&&pid1.length()>=1)
{
hql.append(" and ad.pid like '%"+pid1+"%' ");
}
HttpSession session=request.getSession();
session.setAttribute("hql", hql.toString());
int totalPage=countPage();
List mlist=service.getStudent(hql.toString());
request.setAttribute("currPage", "1");
request.setAttribute("previous", "1");
request.setAttribute("next", new Integer((1<totalPage)?2:totalPage));
request.setAttribute("totalPage", String.valueOf(totalPage));
request.setAttribute("mlist", mlist);
return this.SUCCESS;
}
public String save() throws Exception {
System.out.println("save~~~~~~~~~");
HttpServletRequest request=ServletActionContext.getRequest();
String flag=request.getParameter("flag");
if("".equals(flag)||flag==null)
{
Student student=new Student();
student.setSname(sname);
student.setSex(sex);
student.setBirthday(birthday);
student.setPid(pid);
student.setCname(cname);
// student.setTname(tname);
student.setPassword(password);
student.setSnational(national);
student.setOrigin(origin);
student.setUsername(susername);
service.save(student);
}
if("update".equals(flag))
{
String cid=request.getParameter("cid");
Student student=(Student)service.findById(Integer.valueOf(cid));
if(student!=null)
{
//BeanUtils.copyProperties(clazz, memberForm);
student.setSname(sname);
student.setSex(sex);
student.setBirthday(birthday);
student.setPid(pid);
student.setCname(cname);
// student.setTname(tname);
student.setPassword(password);
student.setSnational(national);
student.setOrigin(origin);
student.setUsername(susername);
service.updateStudent(student);
}
/*String cid=request.getParameter("cid");
Clazz clazz=(Clazz)dao.findById(Integer.valueOf(cid));
if(clazz!=null)
{
BeanUtils.copyProperties(clazz, memberForm);
dao.update(clazz);
}*/
}
return this.SUCCESS;
}
@Override
public String execute() throws Exception {
/*
Manager manager = service.findManagerByName(username);
//ActionServlet a=ActionContext.
HttpServletRequest request=ServletActionContext.getRequest();
if(manager==null)
{
request.setAttribute("msg", "0");//不存在用户
return this.INPUT;
}
else
{
if(password.equals(manager.getPassword()))
{
System.out.println("密码对了");
//request.setAttribute("msg", "1");
HttpSession session=request.getSession();
session.setAttribute("username", username);
return this.SUCCESS;
}
else
{
System.out.println("密码错误了");
request.setAttribute("msg", "1");
return this.INPUT;
}
}
*/
System.out.println("~~~~~~~~StudentAction success");
return SUCCESS;
}
public int countPage()
{
int count=0;
int total=service.count();
int n=total%10;
if(n==0)
count=total/10;
else
count=total/10+1;
return count;
}
public StudentService getService() {
return service;
}
public void setService(StudentService service) {
this.service = service;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
// public String getTname() {
//
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
高校学生在线选课系统(java) (302个子文件)
.classpath.bak 411B
StudentAction.class 9KB
TeacherAction.class 8KB
MyclassAction.class 7KB
ClassstuAction.class 7KB
SelectTeacherAction.class 6KB
Student.class 3KB
LoginAction.class 3KB
SelectTeacherDAOImpl.class 3KB
MyclassDAOImpl.class 3KB
Teacher.class 2KB
TeacherDAOImpl.class 2KB
ClassstuDAOImpl.class 2KB
StudentDAOImpl.class 2KB
Classstu.class 2KB
UserDAOImpl.class 2KB
Myclass.class 2KB
SelectTeacherServiceImpl.class 2KB
MyclassServiceImpl.class 2KB
StudentServiceImpl.class 2KB
ClassstuServiceImpl.class 2KB
TeacherServiceImpl.class 2KB
Manager.class 2KB
UserServiceImpl.class 1KB
SaveKindnoAction.class 1KB
LogoffAction.class 877B
SelectTeacherService.class 533B
SelectTeacherDAO.class 521B
MyclassService.class 438B
MyclassDAO.class 433B
ClassstuService.class 429B
ClassstuDAO.class 417B
TeacherService.class 414B
StudentService.class 414B
TeacherDAO.class 409B
StudentDAO.class 406B
UserService.class 361B
UserDAO.class 353B
.classpath 7KB
datepicker.css 5KB
datepicker.css 5KB
datepicker.css 4KB
Main.Css 2KB
Styles_Home.css 2KB
login.css 1KB
style.css 923B
grid.css 734B
table.css 605B
WdatePicker.css 158B
Thumbs.db 61KB
Thumbs.db 15KB
Thumbs.db 6KB
Thumbs.db 5KB
Thumbs.db 3KB
login_08.gif 25KB
login_03.gif 19KB
login_05.gif 7KB
login_07.gif 5KB
main_09.gif 5KB
main_30.gif 3KB
main_40.gif 3KB
main_03.gif 3KB
main_32.gif 2KB
main_04.gif 2KB
main_29.gif 2KB
img.gif 2KB
main_48.gif 2KB
main_47.gif 2KB
login_06.gif 2KB
img.gif 2KB
delete1.gif 1KB
main_11.gif 1KB
main_22.gif 1KB
main_12.gif 1KB
datePicker.gif 1KB
main_18.gif 1024B
main_14.gif 991B
main_16.gif 966B
main_20.gif 964B
main_58.gif 804B
main_07.gif 701B
main_37.gif 661B
main_05.gif 640B
main_31.gif 552B
dl.gif 377B
main_21.gif 317B
main_34.gif 292B
maxmum.gif 203B
main_36.gif 203B
main_55.gif 201B
main_55_1.gif 201B
bg.gif 160B
left.gif 124B
main_59.gif 93B
main_62.gif 92B
main_52.gif 79B
main_51.gif 77B
navRight.gif 71B
navLeft.gif 71B
left.gif 65B
共 302 条
- 1
- 2
- 3
- 4
资源评论
- 大象蚂蚁2013-07-04不知道是我配置问题 还是什么原因 就是运行不起来,不过里面的设计模式还是挺不错的
- playboy3072017-06-22积分都给了,下载不了,,,什么鬼啊
- mv9muyfs2014-05-30值得参考 相当不错
- lsnaimei2013-07-03不错的一份代码,可以借用一下
- hsaily2018-01-14还没有用过,非要评论呢 我去试试
haoyaqilk
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功