前提・実現したいこと
ボタンを押したときに
http://XXXXX/bunkiを呼び出していたものを
http://XXXXX/apps/bunkiというURLの呼び出しに変更したいです。
該当のソースコード
元々http://XXXXX/bunkiという作りで処理を呼び出すということだったので以下のように作っていました。
/hello→簡単な認証→trueなら/ok(OKと表示するだけのページ)へ、falseなら/helloに戻るといった処理です。
ボタン側のHTML
<!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>index</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta charset="UTF-8" /> <link rel="stylesheet" href="webjars/bootstrap/4.4.1/css/bootstrap.min.css" /> <script src="webjars/bootstrap/4.4.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <p class="text-center text-danger" th:text="${message}" /> <form th:action="@{/bunki}" th:object="${info}" method="post"> <div class="d-block mx-auto col-md-4"> <div class="form-group"> <input type="text" class="form-control" placeholder="id" th:field="*{id}"> </div> <div class="form-group"> <input type="text" class="form-control" placeholder="pw" th:field="*{pw}"> </div> <div class="form-group"> <input type="submit" class="form-control btn-primary" value="決定"> </div> </div> </form> </div> </body> </html>
コントローラー
@Controller public class MainController { @GetMapping("/hello") public String hello(@ModelAttribute("info") LoginInfoBean info) { return "hello"; } @PostMapping("/bunki") public String bunki(@ModelAttribute("info") LoginInfoBean info, RedirectAttributes redirectAttributes) { String id = info.getId(); String pw = info.getPw(); if(id.equals("1") && pw.equals("1")) { return "redirect:ok"; } redirectAttributes.addFlashAttribute("message", "認証に失敗しました"); redirectAttributes.addFlashAttribute("info", info); return "redirect:hello"; } @GetMapping("/ok") public String ok() { return "ok"; } }
試したこと
しかし、/bunkiの前に/appsを入れてhttp://XXXXX/apps/bunkiとして呼び出すようにといわれました。
そのため以下のように上記を修正しました。
HTML
<form th:action="@{/apps/bunki}" th:object="${info}" method="post">
コントローラー
@Controller public class MainController { @GetMapping("/apps/hello") public String hello(@ModelAttribute("info") LoginInfoBean info) { return "hello"; } @PostMapping("/apps/bunki") public String bunki(@ModelAttribute("info") LoginInfoBean info, RedirectAttributes redirectAttributes) { String id = info.getId(); String pw = info.getPw(); if(id.equals("1") && pw.equals("1")) { return "redirect:ok"; } redirectAttributes.addFlashAttribute("message", "認証に失敗しました"); redirectAttributes.addFlashAttribute("info", info); return "redirect:hello"; } @GetMapping("/apps/ok") public String ok() { return "ok"; } }
発生している問題・エラーメッセージ
ローカル上で上記を試すと問題なく今まで通りの動きをするように見えるのですが、実際にサーバーで公開してボタンを押すと
https://XXXX/bubki(←ブラウザ上で見えるURL) The requested URL /bunki was not found on this server.
と表示されてしまいます。
なぜサーバー上ではうまくいかないでしょうか?
あなたの回答
tips
プレビュー