いつもお世話になっております。
ログインした情報をsessionに保存し、そのsessionからログイン情報を
引き出し画面上に表示する方法について質問があります。
現在、springframeworkを使用しております。
下記のlogin.htmlでユーザ名、パスワードを入力しログイン後
html
1//login.html 2<!DOCTYPE html> 3<html xmlns:th="http://www.thymeleaf.org"> 4<head> 5<title>top page</title> 6<meta http-equiv="Content-Type" 7content="text/html" charset="UTF-8"/> 8 9<!-- css --> 10 11<style> 12 html { height: 100% } 13 body { height: 100%; margin: 0; padding: 0 } 14</style> 15</head> 16<body> 17<form action="/processLogin" method="POST"> 18 <dl> 19 <dt> 20 ログイン名前 21 </dt> 22 <dd> 23 <input type="text" name="name"></input> 24</dd> 25 <dt> 26 ログインパスワード 27 </dt> 28 <dd> 29 <input type="password" name="password"></input> 30 </dd> 31 </dl> 32 <button>ログイン</button> 33 </form> 34</body> 35</html>
下記のfirst.htmlに画面遷移します。
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 16</head> 17<body> 18 <form action="/mailsend" method="POST"> 19 <button>メール送信</button> 20 </form> 21 <hr/> 22 <form action="urlForUpload" enctype="multipart/form-data" method="post"> 23 <div class="form-group"> 24 <label>■ファイル種類:</label> 25 <select id="select_file_type" name="select_file_type" required=""> 26 <option value="login-user">ログインユーザー</option> 27 <!-- アップロードするファイルを定義していく --> 28 </select> 29 </div> 30 <div class="form-group"> 31 <label>■ファイルパス:</label> 32 <input type="file" id="upload_file" name="upload_file" required="" /> 33 </div> 34 <div class="form-group"> 35 <input id="data_upload_button" type="submit" value="アップロード" /> 36 </div> 37 </form> 38 <table> 39 40</table> 41</body> 42</html>
first.htmlに画面遷移した際に、ログインした情報(DBに登録したカラム)
を表示したいと考えております。
※(例)田中さんでログインした際に、first.htmlの画面上にDBに登録してある田中さんの住所や電話番号が表示させるようにしたいです。
調査したところ、@SessionAttributesを使用し、田中さんのオブジェクト
を格納してfirst.htmlからアクセスできるようにすればいいということがわかりました。
しかし、以下の点でつまずいております。
①ログインしたユーザの情報を引き出す方法
※ログインしたユーザのIDを取得して、そのIDを元にログインユーザの
住所や電話番号を取得するのかと思ったのですが、ユーザ名とパスワード
だけの情報からどうやってIDを引き出したらいいのかが不明です。
以上です。情報が少なくて大変申し訳ございませんがご教授宜しくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/02 07:46