wuheng 2 년 전
부모
커밋
ade6285b87

+ 0 - 2
day07/web/form.html

@@ -10,8 +10,6 @@
     <input type="text" onblur="onblurfunc" name="username" />
     <input type="submit" value="提交">
 </form>
-
-
 <script>
     const usernameInput = document.getElementsByName("username")[0]
     usernameInput.onblur = function(){

+ 11 - 0
day08/web/WEB-INF/web.xml

@@ -24,10 +24,21 @@
         <url-pattern>/http</url-pattern>
     </servlet-mapping>
 
+
+
+
     <servlet>
         <servlet-name>UrlDemo</servlet-name>
         <servlet-class>com.lovecoding.servlet.UrlDemoServlet</servlet-class>
+        <init-param>
+            <param-name>timeout</param-name>
+            <param-value>60</param-value>
+        </init-param>
     </servlet>
+
+
+
+
     <!-- .html 后缀的 有可能是 伪静态  -->
     <!-- .do 一般是某个框架的使用习惯  -->
     <!-- /user/login 路径模式  -->

+ 34 - 0
day10/pom.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.lovecoding</groupId>
+    <artifactId>day10</artifactId>
+    <version>0.0.1</version>
+
+    <dependencies>
+
+        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.27</version>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>jstl</artifactId>
+            <version>1.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>taglibs</groupId>
+            <artifactId>standard</artifactId>
+            <version>1.1.2</version>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 79 - 0
day10/src/com/lovecoding/doman/Brand.java

@@ -0,0 +1,79 @@
+package com.lovecoding.doman;
+
+public class Brand {
+    private int id;
+    private String brandName;
+    private String companyName;
+    private int ordered;
+    private String description;
+    private int status;
+
+    public Brand(int i, String brandName, String companyName, int i1, String description, int i2) {
+        this.id = i;
+        this.brandName = brandName;
+        this.companyName = companyName;
+        this.description = description;
+        this.ordered = i1;
+        this.status = i2;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
+
+    public String getCompanyName() {
+        return companyName;
+    }
+
+    public void setCompanyName(String companyName) {
+        this.companyName = companyName;
+    }
+
+    public int getOrdered() {
+        return ordered;
+    }
+
+    public void setOrdered(int ordered) {
+        this.ordered = ordered;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    @Override
+    public String toString() {
+        return "Brand{" +
+                "id=" + id +
+                ", brandName='" + brandName + '\'' +
+                ", companyName='" + companyName + '\'' +
+                ", ordered=" + ordered +
+                ", description='" + description + '\'' +
+                ", status=" + status +
+                '}';
+    }
+}

+ 61 - 0
day10/src/com/lovecoding/doman/User.java

@@ -0,0 +1,61 @@
+package com.lovecoding.doman;
+
+public class User {
+
+    private int id;
+    private String username;
+    private String password;
+    private String gender;
+    private String addr;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getGender() {
+        return gender;
+    }
+
+    public void setGender(String gender) {
+        this.gender = gender;
+    }
+
+    public String getAddr() {
+        return addr;
+    }
+
+    public void setAddr(String addr) {
+        this.addr = addr;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+                "id=" + id +
+                ", username='" + username + '\'' +
+                ", password='" + password + '\'' +
+                ", gender='" + gender + '\'' +
+                ", addr='" + addr + '\'' +
+                '}';
+    }
+}

+ 16 - 0
day10/web/404.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 10:34
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page isErrorPage="true" contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>404</title>
+</head>
+<body>
+<h1>哎呀  页面被外星人偷走了!!!</h1>
+</body>
+</html>

BIN
day10/web/WEB-INF/lib/el-api.jar


BIN
day10/web/WEB-INF/lib/jsp-api.jar


BIN
day10/web/WEB-INF/lib/servlet-api.jar


+ 6 - 0
day10/web/WEB-INF/web.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
+         version="4.0">
+</web-app>

+ 73 - 0
day10/web/demo.jsp

@@ -0,0 +1,73 @@
+<%@ page import="com.lovecoding.doman.User" %><%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 14:04
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+    <table border="1">
+        <tr>
+            <td>ID</td>
+            <td>名字</td>
+            <td>性别</td>
+        </tr>
+        <%
+            for (int i = 0; i < 10; i++) {
+        %>
+        <tr>
+            <td><%=i%></td>
+            <td>名字</td>
+            <td>性别</td>
+        </tr>
+        <%
+            }
+        %>
+    </table>
+
+
+    <%!
+        User user = new User();
+    %>
+    <%
+        User user = new User();
+    %>
+
+    <%
+        out.print("<form id=\"register\" action=\"#\" >\n" +
+                "    <input type=\"text\" onblur=\"onblurfunc\" name=\"username\" />\n" +
+                "    <input type=\"submit\" value=\"提交\">\n" +
+                "</form>\n" +
+                "<script>\n" +
+                "    const usernameInput = document.getElementsByName(\"username\")[0]\n" +
+                "    usernameInput.onblur = function(){\n" +
+                "        if ( this.value.length < 6 ) {\n" +
+                "            alert(\"长度不允许小于6位\")\n" +
+                "            this.value = \"\"\n" +
+                "        }\n" +
+                "    }\n" +
+                "    function submit(){\n" +
+                "        const username = usernameInput.value\n" +
+                "        if ( username ) {\n" +
+                "            return true\n" +
+                "        }\n" +
+                "        alert(\"用户名必须输入\")\n" +
+                "        return false\n" +
+                "    }\n" +
+                "    document.querySelector(\"#register\").onsubmit = submit\n" +
+                "</script>\n");
+    %>
+
+<%
+
+    out.print( application.getAttribute("age") );
+
+%>
+
+</body>
+</html>

+ 57 - 0
day10/web/demo/Eldemo.jsp

@@ -0,0 +1,57 @@
+<%@ page import="com.lovecoding.doman.Brand" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Iterator" %><%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 15:19
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+<%
+    // 查询数据库
+    List<Brand> brands = new ArrayList<Brand>();
+    brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠,好吃不上火",1));
+    brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库,服适人生",0));
+    brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
+%>
+
+<h4 style="text-align: center;">商品表格</h4>
+<table border="1" cellspacing="0" width="800" align="center">
+    <tr align="center">
+        <td><b>序号</b></td>
+        <td><b>LOGO</b></td>
+        <td><b>商品</b></td>
+        <td><b>企业</b></td>
+    </tr>
+    <%
+        Iterator<Brand> iterator = brands.iterator();
+        while ( iterator.hasNext() ) {
+            Brand next = iterator.next();
+            request.setAttribute("next", next);
+    %>
+    <tr align="center">
+        <td>${next.id}</td>
+        <td><img src="https://p0.itc.cn/images01/20210304/095a3fabfc7e48fdbcdb16e5df45d3fe.jpeg" width="30"></td>
+        <td>${next.brandName}</td>
+        <td>${next.companyName}</td>
+    </tr>
+    <%
+            /**
+             * EL 表达式 的用途
+             * EL 他没有空指针的顾虑, 也没有数组下标越界的担心, 非常的自由
+             * EL 作用就是 在四个域内 查找KEY值 并输出到页面上
+             * EL 没有字符串拼接功能
+             * EL param cookie header initParam  内置对象
+             */
+        }
+    %>
+</table>
+</body>
+</html>

+ 59 - 0
day10/web/demo/brands.jsp

@@ -0,0 +1,59 @@
+<%@ page import="com.lovecoding.doman.Brand" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Iterator" %><%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 14:42
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+    <%
+        // 查询数据库
+        List<Brand> brands = new ArrayList<Brand>();
+        brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠,好吃不上火",1));
+        brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库,服适人生",0));
+        brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
+    %>
+
+    <h4 style="text-align: center;">商品表格</h4>
+    <table border="1" cellspacing="0" width="800" align="center">
+        <tr align="center">
+            <td><b>序号</b></td>
+            <td><b>LOGO</b></td>
+            <td><b>商品</b></td>
+            <td><b>企业</b></td>
+        </tr>
+        <%
+            Iterator<Brand> iterator = brands.iterator();
+            while ( iterator.hasNext() ) {
+                Brand next = iterator.next();
+        %>
+        <tr align="center">
+            <td><%=next.getId()%></td>
+            <td><img src="https://p0.itc.cn/images01/20210304/095a3fabfc7e48fdbcdb16e5df45d3fe.jpeg" width="30"></td>
+            <td><%=next.getBrandName()%></td>
+            <td><%=next.getCompanyName()%></td>
+        </tr>
+        <%
+            }
+        %>
+    </table>
+
+    <%
+        /**
+         * JSP 四大域  数据的作用域
+         * page 只限于 当前页面
+         * request 只限于一次请求
+         * session 只限于一次会话
+         * application 整个应用
+         */
+    %>
+</body>
+</html>

+ 54 - 0
day10/web/demo/jstldemo.jsp

@@ -0,0 +1,54 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ page import="com.lovecoding.doman.Brand" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.List" %><%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 15:44
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+<%
+    List<Brand> brands = new ArrayList<Brand>();
+    brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠,好吃不上火",1));
+    brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库,服适人生",0));
+    brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
+    pageContext.setAttribute("brands", brands);
+%>
+
+<h4 style="text-align: center;">商品表格</h4>
+<table border="1" cellspacing="0" width="800" align="center">
+    <tr align="center">
+        <td><b>序号</b></td>
+        <td><b>LOGO</b></td>
+        <td><b>商品</b></td>
+        <td><b>企业</b></td>
+    </tr>
+
+
+
+    <c:forEach items="${brands}" var="next"  >
+    <c:if test="${next.id > 1}"  >
+        <tr align="center">
+            <td>${next.id}</td>
+            <td><img src="https://p0.itc.cn/images01/20210304/095a3fabfc7e48fdbcdb16e5df45d3fe.jpeg" width="30"></td>
+            <td>${next.brandName}</td>
+            <td>${next.companyName}</td>
+        </tr>
+    </c:if>
+</c:forEach>
+
+
+    <c:forEach begin="0" end="10" var="i" step="1" varStatus="status" >
+        ${i} ------ ${status.index + 1 }  <br />
+    </c:forEach>
+
+</table>
+</body>
+</html>

+ 19 - 0
day10/web/footer.jsp

@@ -0,0 +1,19 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 10:44
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<ul>
+    <li>关于我们</li>
+    <li>联系我们</li>
+    <li>联系客服</li>
+    <li>合作招商</li>
+    <li>商家帮助</li>
+    <li>营销中心</li>
+    <li>手机京东</li>
+    <li>友情链接</li>
+
+</ul>

+ 15 - 0
day10/web/header.jsp

@@ -0,0 +1,15 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 10:44
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<ul>
+    <li><a href="index.jsp"> 首页 </a></li>
+    <li><a href="phone.jsp">花费充值</a></li>
+    <li>生活缴费</li>
+    <li>优品推荐</li>
+    <li>登陆页面</li>
+</ul>

+ 59 - 0
day10/web/index.jsp

@@ -0,0 +1,59 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 9:45
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page session="true" contentType="text/html;charset=UTF-8" language="java" %>
+<%@ page  import="com.mysql.cj.MysqlConnection" %>
+<%@ page import="java.io.PrintWriter" %>
+<%@ page import="java.util.Enumeration" %>
+<html>
+  <head>
+    <title>day10页面</title>
+  </head>
+  <body>
+
+  <%@ include file="header.jsp"%>
+  <%
+    int var = 1;
+    //触发异常 走Error页面
+    //int a = 1 / 0;
+  %>
+  <h1> 我是首页 </h1>
+<%--  <%=var%>--%>
+<%--
+  out.print(var);
+--%>
+  <%! int s = 100; %>
+  <%  int s = 100; %>
+
+
+  <%
+
+//      out.print("1234");
+
+    String name = request.getParameter("name");
+
+    HttpSession session1 = request.getSession(true);
+
+    Object user = request.getAttribute("User");
+
+    String contextPath = request.getContextPath();
+
+    PrintWriter writer = response.getWriter();
+
+    String timeout = config.getInitParameter("timeout");
+    Enumeration<String> initParameterNames = config.getInitParameterNames();
+    config.getServletContext();
+    request.getServletContext();
+
+
+    out.print(name);
+  %>
+
+
+  <%@ include file="footer.jsp"%>
+  </body>
+</html>

+ 20 - 0
day10/web/phone.jsp

@@ -0,0 +1,20 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/6
+  Time: 11:00
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+
+<%@ include  file="header.jsp"%>
+    <h1>我是花费充值页面</h1>
+<%@ include file="footer.jsp"%>
+
+</body>
+</html>