
前提・実現したいこと
springでwebサイトを作成しています。
home画面にログイン画面があるので、そこにemailとpassを入力しクリックするとloginSucページに飛ぶ想定です。画面遷移がきちんとできるかの確認の段階なのでspringsecurityの設定などは全てコメントアウトしてあります。他のお問い合わせフォームなどは想定どおり遷移しています。
にも関わらず、homeからloginSucへの画面だけうまく遷移せず、404エラーが発生してしまいます。
発生している問題・エラーメッセージ
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 05 18:46:56 JST 2019 There was an unexpected error (type=Not Found, status=404). No message available
該当のソースコード
controller
java
1package com.example.demo; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Controller; 5import org.springframework.web.bind.annotation.GetMapping; 6import org.springframework.web.bind.annotation.PostMapping; 7import org.springframework.web.bind.annotation.RequestParam; 8import org.springframework.web.servlet.ModelAndView; 9 10import com.example.repositories.UserDataRepository; 11 12 13@Controller 14public class HomeController { 15 16@Autowired 17UserDataRepository repository; 18 19 @GetMapping(value="/") 20 public String home(){ 21 22 return "home"; 23 } 24 @PostMapping(value="/") 25 public ModelAndView login(ModelAndView mv, 26 @RequestParam("email")String email, 27 @RequestParam("pass")String pass 28 ){ 29 mv.setViewName("loginSuc"); 30 mv.addObject("email",email); 31 mv.addObject("pass",pass); 32 33 return mv; 34 } 35} 36
home.html
html
1<!DOCTYPE html> 2<html lang="ja"> 3 <head> 4 <meta charset="utf-8"> 5 <title>CSS Cafe</title> 6 <meta name="description" content="CSS Cafeの公式webサイトです。商品情報、店舗紹介、アクセス、会社情報"> 7 <meta name="keywords" content="CSS Cafe, カフェ,コーヒー"> 8 <link href="/css/html5reset-1.6.1.css" th:href="@{css/html5reset-1.6.1.css}" rel="stylesheet"></link> 9 <link href="/css/home.css" th:href="@{/css/home.css}" rel="stylesheet"></link> 10 </head> 11 <body id="home"> 12 <header id="top"> 13 <h1>CSS Cafe</h1> 14 15 <nav> 16 <ul class="clearfix"> 17 <li class="current"><a href="index.html">ホーム</a></li> 18 <li><a href="#">商品情報</a></li> 19 <li><a href="#">店舗紹介</a></li> 20 <li><a href="#">アクセス</a></li> 21 <li><a href="#">会社情報</a></li> 22 <li><a href="quetionForm">お問い合わせ</a></li> 23 </ul> 24 </nav> 25 </header> 26 <main class="clearfix"> 27 <div id="main_image"> 28 <img src="https://via.placeholder.com/940x350" alt="CSS Cafe"> 29 </div> 30<div id="main_content"> 31 <section id="info"> 32<h2>お知らせ</h2> 33<dl> 34 <dt>2018年3月10日</dt> 35<dd>リニューアルオープンしました。</dd> 36<dt>2018年4月15日</dt> 37<dd>4/27(金)は設備メンテナンスのため休業いたします。</dd> 38<dt>2018年4月20日</dt> 39<dd>ゴールデンウィークは休まず営業いたします</dd> 40</dl> 41</section> 42<section id="campaign"> 43<h2>キャンペーン情報</h2> 44<ul> 45<li>日頃の感謝を込めて、パスタ全品がいつもよりお得に!</li> 46<li>平日11時から14時までお得なランチタイムを実施中。</li> 47<li>バイオリン演奏付きのスペシャルディナーイベントの早期予約受付中。</li> 48</ul> 49</section> 50</div> 51 52<aside id="sidebar"> 53 <h3>ログイン</h3> 54 <ul> 55 <li> 56 <form class="dropdown-menu p-4" method="post" action="/loginSuc"> 57 <div class="form-group"> 58 <label for="exampleDropdownFormEmail2">Email address</label> 59 <input type="email" class="form-control" id="exampleDropdownFormEmail2" name="email" placeholder="email@example.com"> 60 </div> 61 <div class="form-group"> 62 <label for="exampleDropdownFormPassword2">Password</label> 63 <input type="password" class="form-control" id="exampleDropdownFormPassword2" name="pass" placeholder="Password"> 64 </div> 65 <div class="form-group"> 66 <div class="form-check"> 67 <input type="checkbox" class="form-check-input" id="dropdownCheck2"> 68 <label class="form-check-label" for="dropdownCheck2"> 69 Remember me 70 </label> 71 </div> 72 </div> 73 <button type="submit" class="btn btn-primary">login</button> 74 </form> 75</li> 76<li> 77 <a href="#"> 78 <img src="https://via.placeholder.com/300x200"alt="バナー"> 79</a> 80</li> 81</ul> 82</aside> 83</main> 84<footer> 85 <ul> 86<li><a href="index.html">ホーム</a></li> 87<li><a href="#">商品情報</a></li> 88<li><a href="#">店舗紹介</a></li> 89<li><a href="#">アクセス</a></li> 90<li><a href="#">会社情報</a></li> 91<li><a href="quetionForm">お問い合わせ</a></li> 92</ul> 93<small>©2018 CSS Cafe</small> 94</footer> 95 </body> 96</html> 97
loginSuc.html
html
1<!DOCTYPE html> 2<html lang="ja"> 3 <head> 4 <meta charset="utf-8"> 5 <title>ログイン成功</title> 6 <meta name="description" content="お問い合わせ"> 7 <link rel="stylesheet" href="stylesheets/html5reset-1.6.1.css"> 8 9 </head> 10 <body id="login"> 11 <header id="top"> 12 <h1>ログイン成功</h1> 13 <p>ようこそ</p> 14 </header> 15 </body> 16</html> 17
試したこと
- 階層があっているか確認
- templates以下にhtmlがきちんと配置されているか確認済み
- htmlの"name"がきちんと合っているか確認済み(email,passになっていました)
- home.htmlのactionタグが画面遷移先になっているか確認済み(action="/loginSuc"になっていました)
補足情報(FW/ツールのバージョンなど)
build.gradle(他に必要な情報があれば教えていただけると嬉しいです。)
buildscript { ext { springBootVersion = '2.1.1.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile 'org.slf4j:slf4j-api:1.7.21' compile 'org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE' compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.4.1.RELEASE' compile'com.h2database:h2' compile'org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE' compile'org.springframework.boot:spring-boot-starter-thymeleaf' testCompile('org.springframework.boot:spring-boot-starter-test') }


回答1件
あなたの回答
tips
プレビュー