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

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

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

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

Spring Boot

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

Q&A

解決済

1回答

36686閲覧

springbootで作成した新規登録画面がうまく起動しない

heavyuseman

総合スコア42

Java

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

Spring Boot

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

0グッド

0クリップ

投稿2017/05/23 13:35

編集2017/05/23 13:37

いつもお世話になっております。
springbootでNewAccount画面(新規会員登録画面)を作成しました。
NewAccount画面(新規会員登録画面)を開き、登録する名前とパスワードを入力し
登録ボタンを押下したところ下記のエラーが出ました

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue May 23 22:26:09 JST 2017
There was an unexpected error (type=Forbidden, status=403).
Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

原因が不明ですのでご教授よろしくお願いいたします。

java

1package com.tuyano.springboot.dateaccess; 2 3import org.springframework.data.jpa.repository.JpaRepository; 4import org.springframework.stereotype.Repository; 5 6import com.tuyano.springboot.dateaccess.Newaccount; 7 8@Repository 9public interface DataAccessRepository extends JpaRepository<Newaccount, Integer>{ 10 11} 12

java

1package com.tuyano.springboot.dateaccess; 2 3import javax.persistence.Column; 4import javax.persistence.Entity; 5import javax.persistence.GeneratedValue; 6import javax.persistence.Id; 7 8 9@Entity// このクラスはEntityとして登録しますよ、とspringに教えてます 10public class Newaccount { 11 12 @Id// プライマリーキーのものに設定してください 13 @GeneratedValue// 主に数字に対して、順番に一意に設定しますよ、の意味 14 private Integer ID; 15 16 @Column// ただの変数じゃなくて、DBのカラムだよ、の意味 17 private String name; 18 @Column// 19 private int password; 20 21 // setter & getter --------------------- 22 public Integer getID() { 23 return ID; 24 } 25 public String getName(){ 26 return name; 27 } 28 public int getPassword(){ 29 return password; 30 } 31 32 33 public void setEmpID(Integer ID) { 34 this.ID = ID; 35 } 36 37 public void setName(String name) { 38 this.name = name; 39 } 40 41 public void setPassword(int password) { 42 this.password = password; 43 } 44 45 46 47 48 // constructor -------------------------- 49 public Newaccount(){ 50 super(); 51 } 52 53 public Newaccount(Integer ID, String name,int password){ 54 super(); 55 this.ID =ID; 56 this.name = name; 57 this.password = password; 58 59 } 60 61}

java

1package com.tuyano.springboot.app; 2 3import java.util.List; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7import org.springframework.http.MediaType; 8import org.springframework.stereotype.Controller; 9import org.springframework.transaction.annotation.Transactional; 10import org.springframework.ui.Model; 11import org.springframework.web.bind.annotation.ModelAttribute; 12import org.springframework.web.bind.annotation.RequestBody; 13import org.springframework.web.bind.annotation.RequestMapping; 14import org.springframework.web.bind.annotation.RequestMethod; 15import org.springframework.web.bind.annotation.RequestParam; 16import org.springframework.web.bind.annotation.ResponseBody; 17import org.springframework.web.servlet.ModelAndView; 18import com.fasterxml.jackson.databind.SerializationFeature; 19import com.fasterxml.jackson.core.JsonProcessingException; 20import com.fasterxml.jackson.databind.ObjectMapper; 21import com.tuyano.springboot.app.Emp; 22import com.tuyano.springboot.app.EmpRepository; 23import com.tuyano.springboot.dateaccess.DataAccessRepository; 24import com.tuyano.springboot.dateaccess.Newaccount; 25 26 27 28@Controller 29@EnableAutoConfiguration 30public class Test { 31 32 @Autowired //リポジトリを紐づけます 33 EmpRepository repository; 34 @Autowired //リポジトリを紐づけます 35 DataAccessRepository dataAccessRepository; 36 @RequestMapping(value="/") 37 @ResponseBody 38 public String home(){ 39 //json値格納変数 40 String jsonvalue; 41 //全件取得します 42 Iterable<Emp> list = repository.findAll(); 43 44 // 取得した内容を出力します 45 for(Emp emp: list){ 46 //Jacksonでオブジェクトを JSON に変換 47 ObjectMapper objectMapper = new ObjectMapper(); 48 try { 49 jsonvalue = objectMapper.writeValueAsString(emp); 50 System.out.println("jsonの値"+jsonvalue); 51 return jsonvalue; 52 }catch (JsonProcessingException e) { 53 e.printStackTrace(); 54 } 55 } 56 return null; 57 58 } 59 //first画面呼び出し 60 @RequestMapping(value="/first",method=RequestMethod.GET) 61 public String find(){ 62 63 return null; 64 } 65 //NewAccount画面呼び出し 66 @RequestMapping(value="/NewAccount",method=RequestMethod.GET) 67 public String NewAccount(){ 68 69 return null; 70 } 71 //NewAccount画面呼び出し 72 @RequestMapping(value="/NewAccount",method=RequestMethod.POST) 73 @Transactional(readOnly=false) 74 public ModelAndView register(@ModelAttribute("formModel") Newaccount newaccount,ModelAndView mav){ 75 System.out.println("newaccountは"+newaccount); 76 dataAccessRepository.saveAndFlush(newaccount); 77 return new ModelAndView("redirect:/NewAccount"); 78 } 79 80 81}

html

1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<title>top page</title> 5<meta http-equiv="Content-Type" 6content="text/html" charset="UTF-8"/> 7 8<!-- css --> 9 10<style> 11 html { height: 100% } 12 body { height: 100%; margin: 0; padding: 0 } 13 #map { height: 100% } 14</style> 15</head> 16<body> 17 18 <h1 th:text="${title}">find Page</h1> 19 <table> 20 <form method="post" action="/NewAccount" th:object="${formModel}"> 21 <tr><td>名前</td> 22 <td><input type="text" id="name" name="name" size="20" th:value="${name}"/></td></tr> 23 <tr><td>パスワード</td> 24 <td><input type="text" id="password" name="password" size="20" th:value="${password}"/></td></tr> 25 <tr><td></td><td><input type="submit" /></td></tr> 26 </form> 27 </table> 28</body> 29</html>

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

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

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

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

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

guest

回答1

0

ベストアンサー

スタックトレースに出ていますように

Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

spring-boot-starter-securityをお使いでしょうか。

SpringSecurityを使ったCSRFトークンチェックを実施しているのに、CSRFトークンチェック用のパラメータまたはHTTPヘッダが入っていないようです。

以下の公式サイトにも書かれていますが、
http://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html#csrf-include-csrf-token

Spring MVCのform:formタグか or Thymeleaf 2.1以降でかつ @EnableWebSecurityを設定している場合なら、CsrfTokenは自動的に埋め込まれます。

投稿2017/05/24 02:41

A-pZ

総合スコア12011

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

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

heavyuseman

2017/05/24 11:37

ご回答ありがとうございます。上記の通りに修正したところ無事エラーが解決しました。
A-pZ

2017/05/24 14:09

Σ d(・ω・
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問