📄 projectaction.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-12-2007
*
* XDoclet definition:
* @struts.action path="/project" name="projectForm" input="/project/insert.jsp" scope="request"
*/
public class ProjectAction 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 {
ProjectForm projectForm = (ProjectForm) form;
request.setCharacterEncoding("gb2312");
HttpSession session = request.getSession();
String mark = new String();
String name = projectForm.getName();
if(name!=null ) name = new String(name.getBytes("iso8859_1"), "gb2312");
if (name == null) {
name = "";
}
String brief = projectForm.getBrief();
if(brief!=null ) brief = new String(brief.getBytes("iso8859_1"), "gb2312");
if (brief == null) {
brief = "";
}
String startTime = projectForm.getStartTime();
if(startTime!=null ) startTime = new String(startTime.getBytes("iso8859_1"), "gb2312");
if (startTime == null) {
startTime = "";
}
int pid = Integer.parseInt(projectForm.getPid());
String[] check = projectForm.getCheck();
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String command = projectForm.getCommand();
if(command!=null) {
command = command.trim();
command = new String(command.getBytes("iso8859_1"), "gb2312");
}
System.out.println("要执行的操作是:" + command);
boolean bool = false;
Project project = new Project();
project.setPid(pid);
project.setName(name);
project.setBrief(brief);
project.setStartTime(startTime);
IProjectDAO projectDAO = getProjectService().getProjectDAO();
String condition = new String();
PageBean pageBean = new PageBean();
//添加信息
if (command.equals("insert")) {
bool = projectDAO.saveProject(project);
if (bool) {
out.println("<script language=javascript>alert('添加成功!')");
out.println("location.href='project/query.jsp'</script>");
out.close();
} else {
out.println("<script language=javascript>alert('错误!添加未成功!')");
out.println("location.href='project/query.jsp'</script>");
out.close();
}
}
//查询
if (command.equals("query")) {
// PageBean pageBean = new PageBean();
condition = projectForm.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;
// String url = "query.jsp";
if (request.getParameter("pages")==null) {
currPage =0;
}
else {
currPage = new Integer(request.getParameter("pages")).intValue();
}
System.out.println("Here is currPage!");
pageBean.setPageNum(pageNum);
pageBean.setCurrPage(currPage);
pageBean.setCondition(condition);
ArrayList ls = (ArrayList)projectDAO.getProject(pageBean);
session.setAttribute("queryResult2", ls);
//session.setAttribute("pageBean", pageBean);
mark = "queryPage";
}
//更新信息
if (command.equals("update")) {
bool = projectDAO.updateProject(project);
if (bool) {
out.println("<script language=javascript>alert('修改成功!')");
//out.println("window.close()</script>");
out.println("location.href='project/query.jsp'</script>");
out.close();
} else {
out.println("<script language=javascript>alert('错误!修改未成功!')");
//out.println("window.close()</script>");
out.println("location.href='project/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 = projectDAO.delProject(check[i]);
if (bool) {
out.println("<script language=javascript>alert('删除成功!')");
out.println("location.href='project/query.jsp'</script>");
out.close();
}
else {
out.println("<script language=javascript>alert('删除未成功!')");
out.println("location.href='project/query.jsp'</script>");
out.close();
}
}
}
}
return mapping.findForward(mark);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -