Java 如何使用Springboot从一个html页面重定向到另一个html页面
我正在使用Springboot和Thymeleaf制作一个TictaToe应用程序。但是我面临着将我的Java 如何使用Springboot从一个html页面重定向到另一个html页面,java,html,spring-boot,Java,Html,Spring Boot,我正在使用Springboot和Thymeleaf制作一个TictaToe应用程序。但是我面临着将我的index.html重定向到message.html 这是我的index.html代码 } 有谁能给我一段代码,告诉我如何将它重定向到新的HTML页面,message.HTML。我没有从index.html传递任何特定数据。在href属性上运行时出现以下错误 白标错误页面此应用程序没有/Error的显式映射,因此您将其视为一种回退。首先,我建议您使用ErrorController界面,以便更好地
index.html
重定向到message.html
这是我的index.html代码
}
有谁能给我一段代码,告诉我如何将它重定向到新的HTML页面,message.HTML
。我没有从index.html
传递任何特定数据。在href
属性上运行时出现以下错误
白标错误页面此应用程序没有/Error的显式映射,因此您将其视为一种回退。首先,我建议您使用ErrorController界面,以便更好地跟踪错误所在的位置 至于您的错误,我假设您的其他控制器端点工作正常(如果不是这样,请检查@ComponentScan相关问题),并且您的templates文件夹中有一个message.html模板(如果您没有message.html,那么肯定会出现404错误)。但假设你拥有所有这些:
首先,我建议您使用ErrorController界面,以便更好地跟踪错误所在的位置 至于您的错误,我假设您的其他控制器端点工作正常(如果不是这样,请检查@ComponentScan相关问题),并且您的templates文件夹中有一个message.html模板(如果您没有message.html,那么肯定会出现404错误)。但假设您有所有这些:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>Tic Tac Toe</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/app-main.js"></script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/app-layout.css" />
<link rel="icon" type="image/png" href="images/tic-tac-toe.png" />
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<span class="navbar-brand"> <img alt="Brand"
src="images/tic-tac-toe.png" /> Tic Tac Toe
</span>
</div>
</div>
</nav>
<div class="game-area panel panel-default">
<div class="panel-body">
<h4 class="game-status">
<span th:if="${game.getPlayerState().isInProgress()}"
class="label label-default"> Your turn. Think very carefully
and click a square when ready.</span> <span
th:if="${game.getPlayerState().isWin()}"
class="label label-success"> YOU WIN! Your superior
intellect prevailed and assured a sound victory. Click here to <a
href="/message">view your reward</a>
</span> <span th:if="${game.getPlayerState().isLoss()}"
class="label label-danger"> You've lost. Better luck next
time!</span> <span th:if="${game.getPlayerState().isDraw()}"
class="label label-info"> Mheh! A smelly draw. Beats losing
though, right?</span>
</h4>
<table class="board">
<tr th:each="row : ${game.getBoard().getTiles()}" class="board-row">
<td th:each="tile : ${row}">
<div th:id="${tile.getId()}" class="board-row-tile"
th:classappend="${!tile.isEmpty()} ? ${tile} + '-value' : (${!game.isGameOver()} ? 'available')"
th:text="${tile}"> </div>
</td>
</tr>
</table>
<form id="form_mark_tile" th:action="@{/}" method="POST"
class="form-inline">
<div class="checkbox">
<label><input name="player_go_first" type="checkbox"
th:checked="${game.isPlayerGoFirst()}" /> Play First</label>
</div>
<div class="btn-new-game-wrap">
<a id="btn-new-game" class="btn btn-success btn-lg"
href="javascript:void(0);" role="button">New Game</a>
</div>
<input id="is_game_over" type="hidden"
th:value="${game.isGameOver()}" /> <input id="tile_id"
name="tile_id" type="hidden" value="" /> <input id="new_game"
name="new_game" type="hidden" value="" />
</form>
</div>
</div>
</body>
</html>
@Controller
@SessionAttributes("game")
public class TicTacToeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(@ModelAttribute("game") Game game) {
return "index";
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public String markTile(@ModelAttribute("game") Game game, @RequestParam("tile_id") String tileId,
@RequestParam(value = "new_game", required = false, defaultValue = "false") boolean newGame,
@RequestParam(value = "player_go_first", required = false, defaultValue = "false") boolean playerGoFirst) {
if (newGame) {
game.reset();
game.setPlayerGoFirst(playerGoFirst);
if (!playerGoFirst) {
// give computer a small advantage by always placing X in the center as its
// first move
game.markTile("1-1");
}
} else {
game.markTile(tileId); // Player Turn
game.markTileRandom(); // Computer Turn
}
return "index";
}
@GetMapping(value = "/message")
public String message() {
return "redirect:/message.html";
}
@ModelAttribute("game")
public Game populateGame() {
return new Game();
}