diff --git a/README.md b/README.md index c25fc39..594abff 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,18 @@ 2020年8月24日 + + 0.2.3 + + + + 2020年8月25日 +

配置情况

diff --git a/src/com/supermarket/decorator/HttpServletRequestDecorator.java b/src/com/supermarket/decorator/HttpServletRequestDecorator.java index cdc2f66..dc1a534 100644 --- a/src/com/supermarket/decorator/HttpServletRequestDecorator.java +++ b/src/com/supermarket/decorator/HttpServletRequestDecorator.java @@ -67,7 +67,7 @@ public String getParameter(String name) { String encryptMethod = this.request.getServletContext().getInitParameter("encryptMethod"); if (result == null) return null; - else if ("password".equalsIgnoreCase(name)) + else if ("password".equalsIgnoreCase(name) || "password2".equalsIgnoreCase(name)) // 如果键是password,对其进行加密处理 return WebUtils.encrypt(result[0], encryptMethod); else diff --git a/src/com/supermarket/filter/UseDataSource.java b/src/com/supermarket/filter/UseDataSource.java deleted file mode 100644 index bc3f70c..0000000 --- a/src/com/supermarket/filter/UseDataSource.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.supermarket.filter; - -import com.supermarket.utils.JDBCUtils; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import java.io.IOException; - -@WebFilter(filterName = "UseDataSource") -public class UseDataSource implements Filter { - @Override - public void init(FilterConfig filterConfig) throws ServletException { - String datasource = filterConfig.getServletContext().getInitParameter("datasource"); - JDBCUtils.setPool(datasource); - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - } -} diff --git a/src/com/supermarket/listener/ApplicationListener.java b/src/com/supermarket/listener/ApplicationListener.java index 935b2d3..3ca5e55 100644 --- a/src/com/supermarket/listener/ApplicationListener.java +++ b/src/com/supermarket/listener/ApplicationListener.java @@ -1,5 +1,6 @@ package com.supermarket.listener; +import com.supermarket.utils.JDBCUtils; import org.apache.log4j.Logger; import javax.servlet.ServletContext; @@ -23,10 +24,12 @@ public class ApplicationListener implements ServletContextListener{ // ------------------------------------------------------- /** - * web应用启动回调函数 + * web应用启动回调函数,在其中注册JDBC驱动 * @param sce ServletContext事件 */ public void contextInitialized(ServletContextEvent sce) { + String datasource = sce.getServletContext().getInitParameter("datasource"); + JDBCUtils.setPool(datasource); log.debug("web应用已创建"); } diff --git a/src/com/supermarket/web/AjaxUsernameServlet.java b/src/com/supermarket/web/AjaxUsernameServlet.java index 2113134..7b66173 100644 --- a/src/com/supermarket/web/AjaxUsernameServlet.java +++ b/src/com/supermarket/web/AjaxUsernameServlet.java @@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; -@WebServlet(name = "AjaxUsernameServlet") +@WebServlet(name = "AjaxUsernameServlet", value = "/AjaxUsernameServlet") public class AjaxUsernameServlet extends HttpServlet { private UserService userService = new UserService(); diff --git a/src/com/supermarket/web/LoginServlet.java b/src/com/supermarket/web/LoginServlet.java index 2efcb39..7b211ca 100644 --- a/src/com/supermarket/web/LoginServlet.java +++ b/src/com/supermarket/web/LoginServlet.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.Objects; -@WebServlet(name = "LoginServlet") +@WebServlet(name = "LoginServlet", value = "/LoginServlet") public class LoginServlet extends HttpServlet { private UserService userService = new UserService(); private ValistrService valistrService = new ValistrService(); diff --git a/src/com/supermarket/web/LogoutServlet.java b/src/com/supermarket/web/LogoutServlet.java index 9757f69..2983478 100644 --- a/src/com/supermarket/web/LogoutServlet.java +++ b/src/com/supermarket/web/LogoutServlet.java @@ -10,7 +10,7 @@ import javax.servlet.http.HttpSession; import java.io.IOException; -@WebServlet(name = "LogoutServlet") +@WebServlet(name = "LogoutServlet", value = "/LogoutServlet") public class LogoutServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { this.doGet(request, response); diff --git a/src/com/supermarket/web/RegistServlet.java b/src/com/supermarket/web/RegistServlet.java index 273e0bd..bd3e4c2 100644 --- a/src/com/supermarket/web/RegistServlet.java +++ b/src/com/supermarket/web/RegistServlet.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.sql.SQLException; -@WebServlet(name = "RegistServlet") +@WebServlet(name = "RegistServlet", value = "/RegistServlet") public class RegistServlet extends HttpServlet { private UserService userService = new UserService(); private ValistrService valistrService = new ValistrService(); diff --git a/src/com/supermarket/web/ValiImgServlet.java b/src/com/supermarket/web/ValiImgServlet.java index 2bb9c92..4043e74 100644 --- a/src/com/supermarket/web/ValiImgServlet.java +++ b/src/com/supermarket/web/ValiImgServlet.java @@ -15,7 +15,7 @@ import java.io.IOException; import java.io.OutputStream; -@WebServlet(name = "ValiImgServlet") +@WebServlet(name = "ValiImgServlet", value = "/ValiImgServlet") public class ValiImgServlet extends HttpServlet { private ValistrService valistrService = new ValistrService(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git "a/web/WEB-INF/classes/META-INF/\347\275\221\344\270\212\345\225\206\345\237\216.kotlin_module" "b/web/WEB-INF/classes/META-INF/\347\275\221\344\270\212\345\225\206\345\237\216.kotlin_module" new file mode 100644 index 0000000..a49347a Binary files /dev/null and "b/web/WEB-INF/classes/META-INF/\347\275\221\344\270\212\345\225\206\345\237\216.kotlin_module" differ diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 884536d..f7726f8 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -14,16 +14,6 @@ /* - - - UseDataSource - com.supermarket.filter.UseDataSource - - - UseDataSource - /* - - AutoLogin @@ -64,67 +54,4 @@ md5 - - - RegistServlet - com.supermarket.web.RegistServlet - - datasource - c3p0 - - - - RegistServlet - /RegistServlet - - - - - AjaxUsernameServlet - com.supermarket.web.AjaxUsernameServlet - - datasource - c3p0 - - - - AjaxUsernameServlet - /AjaxUsernameServlet - - - - - ValiImgServlet - com.supermarket.web.ValiImgServlet - - - ValiImgServlet - /ValiImgServlet - - - - - LoginServlet - com.supermarket.web.LoginServlet - - - LoginServlet - /LoginServlet - - - - - LogoutServlet - com.supermarket.web.LogoutServlet - - - LogoutServlet - /LogoutServlet - - - - - com.supermarket.listener.ApplicationListener - - \ No newline at end of file diff --git a/web/js/methods.js b/web/js/methods.js index b04dff7..955b5d1 100644 --- a/web/js/methods.js +++ b/web/js/methods.js @@ -1,19 +1,78 @@ // 判断是否为空 function isNull(element, msg) { let node = $(element); - if (node.val() === ""){ + if (node.val() === "") { // 如果是空 node.nextAll("span").text(msg).css("color", "red"); return true; - }else{ + } else { // 如果非空 node.nextAll("span").text(""); return false; } } +// 正则校验 +function isRegexValid(element, regex, msg) { + let node = $(element); + if (node.val() === "") { + // 空值 + return false; + } else if (regex.test(node.val())) { + // 正则验证通过 + node.nextAll("span").text(""); + return true; + } else { + // 正则不通过 + node.nextAll("span").text(msg).css("color", "red"); + return false; + } +} + +// 值相等校验 +function isEqual(element1, node2, msg) { + let node1 = $(element1); + if (node1.val() === node2.val() && node1.val() !== "" && node2.val() !== "") { + // 二者相等 + node1.nextAll("span").text(""); + node2.nextAll("span").text(""); + return true; + } else if (node1.val() === "" || node2.val() === "") { + // 存在为空的 + } else { + // 二者不相等,对离焦控件做出提示 + node1.nextAll("span").text(msg).css("color", "red"); + return false; + } +} + // 刷新验证码 -function refreshValistr(element){ +function refreshValistr(element) { let time = new Date().getTime(); $(element).attr("src", "/ValiImgServlet?time=" + time); +} + +// 可用性校验 +function isAvailable(element, msg1, msg2, path) { + let node = $(element); + if (node.val() === "") { + // 如果没通过非空校验,直接返回false + node.nextAll("span").text(""); + return false; + } + $.ajax({ + "url": path, + "data": {[node.attr("name")]: node.val()}, + "async": true, + "type": "POST", + "success": function (result) { + if (eval(result)) { + // 用户名可以使用 + node.nextAll("span").text(msg1).css("color", "#00716d"); + } else { + // 用户名不可以使用 + node.nextAll("span").text(msg2).css("color", "red"); + } + } + }); } \ No newline at end of file diff --git a/web/login.jsp b/web/login.jsp index cc1d9fe..ac2f125 100644 --- a/web/login.jsp +++ b/web/login.jsp @@ -21,6 +21,11 @@ // 如果用户名不为空,则记住用户名 $("input[name='remname']").attr("checked", "checked"); } + // 如果支持html5,那么使用自带校验 + if (window.applicationCache){ + $("form").removeAttr("onsubmit"); + $("input").removeAttr("onblur"); + } }) // 提交表单的检查函数 @@ -46,21 +51,21 @@ 用户名: - + 密   码: - + 验证码: - + 验证码 diff --git a/web/regist.jsp b/web/regist.jsp index b16bd5d..9383eff 100644 --- a/web/regist.jsp +++ b/web/regist.jsp @@ -11,113 +11,66 @@