1.设计编写数据库
2.编写dao层及service层
3.(重点)servlet(control)层编写:
package stu.adam.control; import org.omg.CORBA.Request; import stu.adam.entity.Classinfo; import stu.adam.service.ClassinfoService; import stu.adam.service.Impl.ClassInfoServiceImpl; 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 javax.xml.ws.Response; import java.io.IOException; import java.time.Year; import java.util.List; @WebServlet(name = "classinfo", urlPatterns = "/classinfo") public class ClassinfoServlet extends HttpServlet { ClassinfoService classinfoService=new ClassInfoServiceImpl(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); // type:客户端提交的请求类型 String type = request.getParameter("type"); switch (type) { case "show": showClass(request, response); break; } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { this.doPost(request, response); } public void showClass(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { List<Classinfo> classinfoList=classinfoService.checkAllClass(); request.setAttribute("classList",classinfoList); request.getRequestdispatcher("classAction.jsp").forward(request,response); } }
重要代码:
response.sendRedirect("classinfo?type=show");
在获取用户不为空之后请求重定向,切记此处不可以直接跳转jsp,而是应该发出请求,此处请求对应显示班级信息
登入完
显示班级信息开始:
1.设计编写数据库
2.编写dao层及service层
3.servlet层编写:
@WebServlet(name = "classinfo", urlPatterns = "/classinfo") public class ClassinfoServlet extends HttpServlet { ClassinfoService classinfoService=new ClassInfoServiceImpl(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); // type:客户端提交的请求类型 String type = request.getParameter("type"); switch (type) { case "show": showClass(request, response); break; } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { this.doPost(request, response); } public void showClass(HttpServletRequest request, HttpServletResponse response) throws servletexception, IOException { List<Classinfo> classinfoList=classinfoService.checkAllClass(); request.setAttribute("classList",classinfoList); request.getRequestdispatcher("classAction.jsp").forward(request,response); } }
重点代码:
这句话将classinfoList放到jsp里面
request.setAttribute("classList",classinfoList);
这句话只能转发,不能重定向
request.getRequestdispatcher("classAction.jsp").forward(request,response);
目前进度:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。