質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

2649閲覧

Java 問い合わせフォーム作成

kirkir

総合スコア4

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2020/05/13 07:46

前提・実現したいこと

Java
Springとthymeleafを使い、問い合わせフォームを作成中です。
エラーが発生しているのですが、調べても原因がわかりません。どのようにすれば動くでしょうか。

発生している問題・エラーメッセージ

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. There was an unexpected error (type=Internal Server Error, status=500). Error resolving template [form], template might not exist or might not be accessible by any of the configured Template Resolvers org.thymeleaf.exceptions.TemplateInputException: Error resolving template [form], template might not exist or might not be accessible by any of the configured Template Resolvers

該当のソースコード

package com.example.demo.app.inquiry; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/inquiry") public class InquiryController { @GetMapping("/form") public String form(InquiryForm inquiryForm, Model model) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } @PostMapping("/form") public String formGoback(InquiryForm inquiryForm, Model model) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } @PostMapping("/confirm") public String confirm(@Validated InquiryForm inquiryForm, BindingResult result, Model model) { if(result.hasErrors()) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } model.addAttribute("title", "Confirm Page"); return "inquiry/confirm"; } }
package com.example.demo.app.inquiry; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public class InquiryForm { @Size(min = 1, max = 20, message = "Please input 20characters or less") private String name; @NotNull @Email(message = "Invalid E-mail Format") private String email; @NotNull private String contents; public InquiryForm() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getContents() { return contents; } public void setContents(String contents) { this.contents = contents; } }
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title th:text="${title}">Insert title here</title> </head> <body> <div th:replace="~{block/header::headerA}"></div> <h1 th:text="${title}">title</h1> <h2 th:text="${complete}"></h2> <form method="post" action="#" th:action="@{/survey/confirm}" th:object="${surveyForm}"> <label for="age">Age:</label> <input id="age" name="age" type="number" th:value="*{age}"><br> <div th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></div> <label for="email">Satisfaction:</label> <input type="radio" name="satisfaction" value="1" th:checked="*{satisfaction == 1}">1 <input type="radio" name="satisfaction" value="2" th:checked="*{satisfaction == 2}">2 <input type="radio" name="satisfaction" value="3" th:checked="*{satisfaction == 3}">3 <input type="radio" name="satisfaction" value="4" th:checked="*{satisfaction == 4}">4 <input type="radio" name="satisfaction" value="5" th:checked="*{satisfaction == 5}">5<br> <div th:if="${#fields.hasErrors('satisfaction')}" th:errors="*{satisfaction}"></div> <label for="comment">Comment:</label> <textarea name="comment" id="comment" rows="3" cols="40" th:field="*{comment}"></textarea><br> <div th:if="${#fields.hasErrors('comment')}" th:errors="*{comment}"></div> <input type="submit" value="Confirm"> </form> </body> </html>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2020/05/13 08:40

どの操作で出るのでしょう
m.ts10806

2020/05/13 12:23

block/header も提示してください
Yasumichi

2020/05/13 14:19 編集

テンプレートファイルのあるディレクトリは、プロジェクトルートから見て、どこになっていますか?ファイル名は、どうしていますか?
guest

回答1

0

自己解決

header內に間違いがありました。ありがとうございました。

投稿2020/05/14 01:52

kirkir

総合スコア4

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問