<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>boot-01首页</title> </head> <body> <h1>工程首页</h1> <!--相对路径--> <a href="bmi.html">BMI测试</a> <a href="/bmi.html">BMI测试</a> <!--绝对路径 http://localhost:8080/--> </body> </html>
时间: 2023-07-28 08:11:06 浏览: 197
这是一个简单的HTML页面,其中包含了两个链接。第一个链接是相对路径的示例,它指向名为"bmi.html"的文件。第二个链接是绝对路径的示例,它指向根目录下的"bmi.html"文件。
相对路径是相对于当前文件所在位置的路径,而绝对路径是从根目录开始的完整路径。在这个例子中,假设您正在访问的页面位于"http://localhost:8080/",那么第一个链接将指向"http://localhost:8080/bmi.html",而第二个链接将指向"http://localhost:8080/bmi.html"。
请注意,这只是一个静态HTML页面的示例,其中包含了两个简单的链接。在实际的应用程序中,链接可能会指向更复杂的页面或功能。
相关问题
spring-boot-starter-websocket入门demo
好的,下面是一个简单的 Spring Boot WebSocket 入门 demo:
1. 首先,在 pom.xml 文件中引入 `spring-boot-starter-websocket` 依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
```
2. 创建一个简单的 WebSocket 处理器:
```java
@Component
public class WebSocketHandler extends TextWebSocketHandler {
private final List<WebSocketSession> sessions = new CopyOnWriteArrayList<>();
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
sessions.add(session);
session.sendMessage(new TextMessage("连接成功!"));
}
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
for (WebSocketSession webSocketSession : sessions) {
webSocketSession.sendMessage(new TextMessage("客户端说:" + message.getPayload()));
}
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
sessions.remove(session);
}
}
```
3. 创建 WebSocket 配置类:
```java
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
private WebSocketHandler webSocketHandler;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(webSocketHandler, "/ws").setAllowedOrigins("*");
}
}
```
4. 编写一个简单的页面来测试 WebSocket:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebSocket</title>
</head>
<body>
<h1>WebSocket Demo</h1>
<div>
<input type="text" id="input"/>
<button onclick="send()">发送</button>
</div>
<div id="output"></div>
<script>
var socket = new WebSocket("ws://localhost:8080/ws");
socket.onmessage = function(event) {
var output = document.getElementById("output");
output.innerHTML += "<p>" + event.data + "</p>";
};
function send() {
var input = document.getElementById("input");
socket.send(input.value);
input.value = "";
}
</script>
</body>
</html>
```
5. 运行程序,访问 http://localhost:8080/index.html,打开浏览器控制台,输入命令 `socket.send("Hello, WebSocket!")`,即可看到页面上显示出 "客户端说:Hello, WebSocket!"。
希望这个 demo 能帮助到你。
在Spring Boot框架下的web评论系统,用Thymeleaf实现前端设计,给出index.html、comment.html和reply.html文件
index.html:
```html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Comment System</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<h1>Comment System</h1>
<form th:action="@{/comment}" method="post">
<label>Username:</label>
<input type="text" name="username" required>
<br><br>
<label>Comment:</label>
<textarea name="comment" rows="5" required></textarea>
<br><br>
<button type="submit">Submit</button>
</form>
<br><br>
<table>
<tr>
<th>Username</th>
<th>Comment</th>
<th>Date</th>
</tr>
<tr th:each="comment : ${comments}">
<td th:text="${comment.username}"></td>
<td th:text="${comment.comment}"></td>
<td th:text="${comment.date}"></td>
<td><a th:href="@{/reply/{id}(id=${comment.id})}">Reply</a></td>
</tr>
</table>
</body>
</html>
```
comment.html:
```html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Comment System</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<h1>Comment System</h1>
<div class="comment">
<h2 th:text="${comment.username}"></h2>
<p th:text="${comment.comment}"></p>
<p th:text="${comment.date}"></p>
</div>
<br><br>
<form th:action="@{/reply}" method="post">
<input type="hidden" name="commentId" th:value="${comment.id}">
<label>Username:</label>
<input type="text" name="username" required>
<br><br>
<label>Reply:</label>
<textarea name="reply" rows="5" required></textarea>
<br><br>
<button type="submit">Submit</button>
</form>
<br><br>
<ul>
<li th:each="reply : ${replies}">
<p th:text="${reply.username}"></p>
<p th:text="${reply.reply}"></p>
<p th:text="${reply.date}"></p>
</li>
</ul>
</body>
</html>
```
reply.html:
```html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Comment System</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<h1>Comment System</h1>
<div class="comment">
<h2 th:text="${comment.username}"></h2>
<p th:text="${comment.comment}"></p>
<p th:text="${comment.date}"></p>
</div>
<br><br>
<div class="reply">
<h3 th:text="${reply.username}"></h3>
<p th:text="${reply.reply}"></p>
<p th:text="${reply.date}"></p>
</div>
</body>
</html>
```
阅读全文