• 大小: 1.82MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-01
  • 语言: Java
  • 标签:

资源简介

java+html实习数据库增删改查,导入即可运行,含数据库

资源截图

代码片段和文件信息

package entity;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ActionServlet extends HttpServlet {
public void service(HttpServletRequest requestHttpServletResponse response)
throws ServletExceptionIOException{
request.setCharacterEncoding(“utf-8“);
response.setContentType(“text/html;charset=UTF-8“);
PrintWriter out =response.getWriter();

String uri=request.getRequestURI();
String action=uri.substring(uri.lastIndexOf(“/“)+1uri.lastIndexOf(“.“));

EmployeeDAO dao=new EmployeeDAO();
System.out.println(1);
if(action.equals(“list“)){

try{
List emps=dao.findAll();
request.setAttribute(“emps“ emps);

System.out.println(emps+“??????“);


request.getRequestDispatcher(“listEmp.jsp“).forward(request response);
}catch (Exception e) {
e.printStackTrace();
}
}else if(action.equals(“add“)){
String name=request.getParameter(“name“);
double salary=Double.parseDouble(request.getParameter(“salary“));
int age=Integer.parseInt(request.getParameter(“age“));
Employee emp=new Employee();
emp.setName(name);
emp.setSalary(salary);
emp.setAge(age);
try{
dao.save(emp);
response.sendRedirect(“list.do“);
}catch (Exception e) {
e.printStackTrace();
}
}else if(action.equals(“delete“)){
int id=Integer.parseInt(request.getParameter(“id“));
try{
dao.delete(id);
response.sendRedirect(“list.do“);
}catch (Exception e) {
e.printStackTrace();
}
}else if(action.equals(“load“)){
int id=Integer.parseInt(request.getParameter(“id“));
try{
Employee emp=dao.findById(id);
request.setAttribute(“emp“ emp);
request.getRequestDispatcher(“update.jsp“).forward(request response);
}catch (Exception e) {
e.printStackTrace();
}
}else if(action.equals(“update“)){
int id=Integer.parseInt(request.getParameter(“id“));
String name=request.getParameter(“name“);
double salary=Double.parseDouble(request.getParameter(“salary“));
int age=Integer.parseInt(request.getParameter(“age“));
Employee emp=new Employee();
emp.setName(name);
emp.setSalary(salary);
emp.setAge(age);
emp.setId(id);
try{
dao.modify(emp);
response.sendRedirect(“list.do“);
}catch (Exception e) {
e.printStackTrace();
}
}
}


}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-06-25 17:52  jj\
     文件         529  2015-06-25 17:52  jj\.classpath
     目录           0  2015-06-25 17:56  jj\.myeclipse\
     文件         279  2015-06-25 17:52  jj\.mymetadata
     文件        1745  2015-06-25 17:52  jj\.project
     目录           0  2015-06-25 17:52  jj\.settings\
     文件         500  2015-06-25 17:52  jj\.settings\.jsdtscope
     文件         395  2015-06-25 17:52  jj\.settings\org.eclipse.jdt.core.prefs
     文件         444  2015-06-25 17:52  jj\.settings\org.eclipse.wst.common.component
     文件         252  2015-06-25 17:52  jj\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2015-06-25 17:52  jj\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2015-06-25 17:52  jj\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件         646  2015-06-25 17:52  jj\SQL Editor (0).sql
     目录           0  2015-06-25 17:52  jj\WebRoot\
     目录           0  2015-06-25 17:52  jj\WebRoot\meta-INF\
     文件          36  2015-06-25 17:52  jj\WebRoot\meta-INF\MANIFEST.MF
     目录           0  2015-06-25 17:52  jj\WebRoot\WEB-INF\
     目录           0  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\
     目录           0  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\entity\
     文件        3658  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\entity\ActionServlet.class
     文件        1343  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\entity\DBUtil.class
     文件        1655  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\entity\Employee.class
     文件        3402  2015-06-25 17:52  jj\WebRoot\WEB-INF\classes\entity\EmployeeDAO.class
     目录           0  2015-06-25 17:52  jj\WebRoot\WEB-INF\lib\
     文件     1988051  2015-06-25 17:52  jj\WebRoot\WEB-INF\lib\ojdbc6.jar
     文件         542  2015-06-25 17:52  jj\WebRoot\WEB-INF\web.xml
     文件         888  2015-06-25 17:52  jj\WebRoot\addEmp.jsp
     文件        1060  2015-06-25 17:52  jj\WebRoot\listEmp.jsp
     文件        1343  2015-06-25 17:52  jj\WebRoot\update.jsp
     目录           0  2015-06-25 17:52  jj\src\
     目录           0  2015-06-25 17:52  jj\src\entity\
............此处省略4个文件信息

评论

共有 条评论

相关资源