主要:接受页面传过来的数据,然后调用其他层数据操作。返回内容。
例子:显示管理表所有内容
package com.qf.emp.controller; import com.qf.emp.entity.Emp; import com.qf.emp.service.Empservice; import com.qf.emp.service.impl.EmpserviceImpl; import javax.servlet.ServletException; import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(value = "/manager/safe/showEmpController") public class showEmpcontroller extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //System.out.println(11111); Integer id =Integer.valueOf(req.getParameter("id")); Empservice empservice =new EmpserviceImpl(); Emp emp = empservice.showEmp(id); req.setAttribute("emp",emp); req.getRequestDispatcher("/manager/safe/showUpdateEmpInfoJSP").forward(req,resp); } }