pom文件
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jhy</groupId>
<artifactId>sanjin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sanjin</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<!-- servlet依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!--target生成页面位置-->
<resources>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.*</include>
</includes>
<targetPath>META-INF/resources</targetPath>
</resource>
</resources>
</build>
</project>
目录结构,只为测试,每层只有一层,
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>万万没想到登录</title>
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="common/css/login.css" media="all">
<script src="common/js/jquery-3.4.1.min.js" charset="utf-8"></script>
<%--<script src="login/login.js" charset="utf-8"></script>--%>
</head>
<body background="photo/login.jpg" background-size: 100%;
background-repeat: no-repeat>
<div id="login_frame">
<form id="form" action="<%=basePath%>login">
<div>我是大魔王,吼吼吼!!!</div>
<br/>
<p><label class="label_input">用户名</label><input type="text" id="username" name="username" class="text_field" required
oninvalid="setCustomValidity('请输入用户名');" oninput="setCustomValidity('');"/></p>
<p><label class="label_input">密码</label><input type="password" id="password" name="password" class="text_field" required
oninvalid="setCustomValidity('请输入密码');" oninput="setCustomValidity('');"/></p>
<br/>
<br/>
<br/>
<div id="login_control">
<input type="submit" id="btn_login" value="登录" />
<button id="registered" class="layui-btn layui-btn-warm" onclick="reg()">注册</button>
<a id="forget_pwd" href="forget_pwd.html">忘记密码?</a>
</div>
</form>
</div>
</body>
<script>
function reg() {
window.location="<%=basePath%>registered.jsp";
}
</script>
</html>
存在静态资源,springboot默认取static中寻找静态资源,故不用添加static