Eclipseでspring tool4を使用し、色んなサイトを見て勉強しています。
前のページの入力したデータを次のページに表示させようと思っています。
上記URLを入力するとHTTP 500 でページが表示できません。
解決方法など教えてください。
ソースは以下になります。
java
1hello.html 2 3<!DOCTYPE html> 4<html xmlns:th="http://www.thymeleaf.org"> 5<head> 6<meta charset="utf-8"> 7<title>Hello World</title> 8</head> 9<body > 10 <h1>Hello World</h1> 11 <form method="post" action="/hello"> 12 好きな文字を入力:<input type="text" name="text1" th:value="${text_value" /> 13 <input type="submit" value="クリック" /> 14 </form> 15</body> 16</html>
java
1HelloController.java 2 3package com.example.helloworld; 4 5import org.springframework.stereotype.Controller; 6import org.springframework.ui.Model; 7import org.springframework.web.bind.annotation.GetMapping; 8import org.springframework.web.bind.annotation.PostMapping; 9import org.springframework.web.bind.annotation.RequestParam; 10 11@Controller 12public class HelloController { 13 @GetMapping("/hello") 14 public String hello() { 15 return "hello"; 16 } 17 18 @PostMapping("/hello") 19 public String PostRequest(@RequestParam("text1") String str, Model model) { 20 model.addAttribute("sample", str); 21 22 return "helloResponse"; 23 } 24}
java
1HelloResponse.html 2 3<!DOCTYPE html> 4<html xmlns:th="http://www.thymeleaf.org"> 5<head> 6<meta charset="utf-8"> 7<title>ResponseSample</title> 8</head> 9<body > 10 <h1>ResponseSample</h1> 11 <p th:text="${sample}"></p> 12</body> 13</html>
回答1件
あなたの回答
tips
プレビュー