这个版本是没有数据库的,存储于文本需要用到IO流,用到的知识有:登录的form表单以及获取表单数据,bootstrap简单修饰界面,servlet相关知识点如:四大作用域对象存储数据进行交互,session销毁登录状态,cookie实现最后一次访问时间的记录,请求转发(请求域一次请求中有效)用作回显数据,重定向跳转页面,filter乱码过滤器和权限过滤器等等...
流程图:
纯手工作图感觉不错,这才像样么.以后多画.提示思路而且有方向.
Servlet是用来处理逻辑的,jsp是显示页面的,虽然说jsp也是Servlet但是显示页面还是jsp更专业,因为jsp就是个长得像html的Servlet.暂时没有使用mvc模式就contraller做逻辑吧.
登录效果:
登录成功:
查看学生:
记事本作为假数据库存储
登录失败:
登录失败回显数据至登录页面
filter乱码过滤器:
package com.zgl.web.filter; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import java.io.IOException; @WebFilter("/*") public class CharacterEncodingFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); chain.doFilter(req, resp); } public void init(FilterConfig config) throws ServletException { } }
filter权限过滤器:
package com.zgl.web.filter; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebFilter("/*") public class LoginFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { HttpServletRequest request=(HttpServletRequest) req; HttpServletResponse response=(HttpServletResponse) resp; String url = request.getRequestURL().toString().toLowerCase(); System.out.println(url); if (url.contains("css")||url.contains("fonts")||url.contains("login")){ chain.doFilter(request,response); }else if (request.getSession().getAttribute("name")!=null){ chain.doFilter(request,response); }else { response.sendRedirect(request.getContextPath()+"/login.jsp"); } } /* chain.doFilter(req, resp);*/ public void init(FilterConfig config) throws ServletException { } }