资源简介
JavaWeb 基础增删改查,一个 Servlet ,使用反射技术,实现多个表单事件处理。
代码片段和文件信息
package com.hly.jsp.javaWeb.controller;
import com.hly.jsp.javaWeb.dao.EmployeeDao;
import com.hly.jsp.javaWeb.entity.Employee;
import com.hly.jsp.javaWeb.impl.EmployeeDaoImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
/**
* @author :hly
* @github :https://github.com/huangliangyun
* @blog :blog.csdn.net/Sirius_hly
* @date :2018/11/28
*/
@WebServlet(urlPatterns = { “*.do“ })
public class EmployeeServlet extends HttpServlet {
public void doPost(HttpServletRequest request HttpServletResponse response) throws IOException ServletException {
response.setContentType(“text/html;charset=UTF-8“);
doGet(request response);
}
public void doGet(HttpServletRequest request HttpServletResponse response) {
response.setContentType(“text/html;charset=utf-8“);
String url = request.getRequestURI();
String methodName = url.substring(url.lastIndexOf(“/“)+1 url.lastIndexOf(“.“));
Method method = null;
try {
// 使用反射机制获取在本类中声明了的方法
method = getClass().getDeclaredMethod(methodName HttpServletRequest.class HttpServletResponse.class);
// 执行方法
method.invoke(this request response);
} catch (Exception e) {
throw new RuntimeException(“调用方法出错“);
}
}
//增加
public void addEmp(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
Employee employee = new Employee();
employee.setName(request.getParameter(“addName“));
employee.setNote(request.getParameter(“addNote“));
EmployeeDao employeeDao = new EmployeeDaoImpl();
employeeDao.add(employee);
selectAllEmp(requestresponse);
}
//查找全部
public void selectAllEmp(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
EmployeeDao employeeDao = new EmployeeDaoImpl();
List list = employeeDao.selectAll();
request.setAttribute(“list“ list);
request.getRequestDispatcher(“/javaWeb/manage/main.jsp“).forward(request response);
}
//模糊查询
public void selectByEmpName(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
String name = request.getParameter(“selectName“);
EmployeeDao employeeDao = new EmployeeDaoImpl();
List list = employeeDao.query(name);
System.err.println(“list:“+list);
request.setAttribute(“list“ list);
request.getRequestDispatcher(“/javaWeb/manage/main.jsp“).forward(request response);
}
//更新数据
public void updateEmp(HttpServletReq
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-29 22:14 controller\
文件 3969 2018-11-29 20:19 controller\EmployeeServlet.java
目录 0 2018-11-29 22:14 dao\
文件 1833 2018-11-29 19:26 dao\DBConnection.java
文件 513 2018-11-29 20:02 dao\EmployeeDao.java
目录 0 2018-11-29 22:14 entity\
文件 927 2018-11-29 20:06 entity\Employee.java
目录 0 2018-11-29 22:14 impl\
文件 4009 2018-11-29 20:23 impl\EmployeeDaoImpl.java
目录 0 2018-11-29 22:14 javaWeb\
目录 0 2018-11-29 22:14 javaWeb\manage\
文件 1781 2018-11-29 21:33 javaWeb\manage\main.jsp
相关资源
- JSP程序设计习题答案
- java写的物流管理系统+源码
- JavaWeb项目实战
- 简单的jdbc+mysql+jsp实现的增删改查
- jsp连接SQLserver数据库实现增删改查.这
- javaweb课程教学网站基本的增删改查功
-
ba
seServlet.jar - Javaweb 图书管理系统教程
- jsp+mysql在线考试系统论文.rar
- JSP实现web网页访问次数
- javaweb学生选课系统课程设计
- javaweb有关外文文献
- jsplumbtoolkit.js
- JSP实现登录注册连接MySql数据库-初学
- vote投票系统java jsp mysql
- 亲自打的servlet+jsp+2008sqlserver的投票系
- jsp学生身体体质信息管理系统
- 基于jsp的留言板课程设计
- JSP毕业论文英文文献和翻译
- JSP + Servlet 实现 网络相册 源代码
- 网上书店 jsp 完整供参考
- jsp导航条 下拉菜单
- 企业论坛系统 jsp + servlet
- jsp个人信息管理系统
- 基于JavaWeb的博客网站的设计与实现毕
- 企业商品销售管理系统jsp+java+sql
-
ba
seServlet - commons-fileupload-1.2.1.jar与commons-io-1.3.
- 购物车jsp+sql server
- jsp登录页面代码jsp登录页面代码
评论
共有 条评论