java bootstrap+servlet(无框架)+mysql 实现增删改查一

登入功能(只截取重要代码以及流程说明):

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);

目前进度:

 

 











 

相关文章

Bootstrip HTML 查询搜索常用格式模版 &lt;form class=&...
如何在按钮上加红色数字 您可以使用Bootstrap的badge组件来在...
要让两个按钮左右排列,你可以使用 Bootstrap 的网格系统将它...
是的,可以将status设置为布尔类型,这样可以在前端使用复选...
前端工程师一般用的是Bootstrap的框架而不是样式,样式一般自...
起步导入:<linkrel="stylesheet"href="b...