demo.jsp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <%@ page import="com.lovecoding.doman.User" %><%--
  2. Created by IntelliJ IDEA.
  3. User: 武恒
  4. Date: 2023/2/6
  5. Time: 14:04
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <html>
  10. <head>
  11. <title>Title</title>
  12. </head>
  13. <body>
  14. <table border="1">
  15. <tr>
  16. <td>ID</td>
  17. <td>名字</td>
  18. <td>性别</td>
  19. </tr>
  20. <%
  21. for (int i = 0; i < 10; i++) {
  22. %>
  23. <tr>
  24. <td><%=i%></td>
  25. <td>名字</td>
  26. <td>性别</td>
  27. </tr>
  28. <%
  29. }
  30. %>
  31. </table>
  32. <%!
  33. User user = new User();
  34. %>
  35. <%
  36. User user = new User();
  37. %>
  38. <%
  39. out.print("<form id=\"register\" action=\"#\" >\n" +
  40. " <input type=\"text\" onblur=\"onblurfunc\" name=\"username\" />\n" +
  41. " <input type=\"submit\" value=\"提交\">\n" +
  42. "</form>\n" +
  43. "<script>\n" +
  44. " const usernameInput = document.getElementsByName(\"username\")[0]\n" +
  45. " usernameInput.onblur = function(){\n" +
  46. " if ( this.value.length < 6 ) {\n" +
  47. " alert(\"长度不允许小于6位\")\n" +
  48. " this.value = \"\"\n" +
  49. " }\n" +
  50. " }\n" +
  51. " function submit(){\n" +
  52. " const username = usernameInput.value\n" +
  53. " if ( username ) {\n" +
  54. " return true\n" +
  55. " }\n" +
  56. " alert(\"用户名必须输入\")\n" +
  57. " return false\n" +
  58. " }\n" +
  59. " document.querySelector(\"#register\").onsubmit = submit\n" +
  60. "</script>\n");
  61. %>
  62. <%
  63. out.print( application.getAttribute("age") );
  64. %>
  65. </body>
  66. </html>