📄 researcheraction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package actions;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import util.PageBean;
import dao.*;
import service.*;
import beans.*;
import util.*;
/**
* MyEclipse Struts
* Creation date: 10-08-2007
*
* XDoclet definition:
* @struts.action path="/researcher" name="researcherForm" input="/researcher_insert.jsp" scope="request"
*/
public class ResearcherAction extends BaseAction {
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ResearcherForm researcherForm = (ResearcherForm) form;
request.setCharacterEncoding("gb2312");
HttpSession session = request.getSession();
String mark = new String();
String name = researcherForm.getName();
if(name!=null ) name = new String(name.getBytes("iso8859_1"), "gb2312");
if (name == null) {
name = "";
}
String sex = researcherForm.getSex();
if(sex!=null ) sex = new String(sex.getBytes("iso8859_1"), "gb2312");
if (sex == null) {
sex = "";
}
String title = researcherForm.getTitle();
if(title!=null ) title = new String(title.getBytes("iso8859_1"), "gb2312");
if (title == null) {
title = "";
}
String career = researcherForm.getCareer();
if(career!=null ) career = new String(career.getBytes("iso8859_1"), "gb2312");
if (career == null) {
career = "";
}
int rid = Integer.parseInt(researcherForm.getRid());
String[] check = researcherForm.getCheck();
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String command = researcherForm.getCommand();
if(command!=null) {
command = command.trim();
command = new String(command.getBytes("iso8859_1"), "gb2312");
}
System.out.println("要执行的操作是:" + command);
boolean bool = false;
Researcher researcher = new Researcher();
researcher.setRid(rid);
researcher.setName(name);
researcher.setSex(sex);
researcher.setTitle(title);
researcher.setCareer(career);
IResearcherDAO researcherDAO = getResearcherService().getResearcherDAO();
String condition = new String();
PageBean pageBean = new PageBean();
//添加信息
if (command.equals("insert")) {
bool = researcherDAO.saveResearcher(researcher);
if (bool) {
out.println("<script language=javascript>alert('添加成功!')");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
} else {
out.println("<script language=javascript>alert('错误!添加未成功!')");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
}
}
//查询
if (command.equals("query")) {
System.out.println("Here is ResearcherAction");
condition = researcherForm.getCondition();
//if(condition!=null) condition = new String(condition.getBytes("iso8859_1"),"gb2312");
System.out.println("The query condition is: "+condition);
if(condition==null) condition="";
session.setAttribute("condition", condition);
int pageNum = 5;
int currPage=0;
pageBean.setPageNum(pageNum);
pageBean.setCurrPage(currPage);
pageBean.setCondition(condition);
ArrayList ls = (ArrayList)researcherDAO.getResearcher(pageBean);
session.setAttribute("queryResult", ls);
mark = "queryPage";
}
//更新信息
if (command.equals("update")) {
bool = researcherDAO.updateResearcher(researcher);
if (bool) {
out.println("<script language=javascript>alert('修改成功!')");
//out.println("window.close()</script>");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
} else {
out.println("<script language=javascript>alert('错误!修改未成功!')");
//out.println("window.close()</script>");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
}
}
//删除信息
if (command.equals("删除")) {
if (check != null) {
int num = check.length;
for (int i = 0; i <= num - 1; i++) {
System.out.println("check[i]=" + check[i]);
bool = researcherDAO.delResearcher(check[i]);
if (bool) {
out.println("<script language=javascript>alert('删除成功!')");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
}
else {
out.println("<script language=javascript>alert('删除未成功!')");
out.println("location.href='researcher/query.jsp'</script>");
out.close();
}
}
}
}
return mapping.findForward(mark);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -