JSPファイルのformで入力した内容がservletで受け取ろうとしても中身がnullになってしまう原因がわからないので教えていただきたいです。
中身がnullかどうかはデバッグをしていて確認したのですが、原因がわかりませんでした。
Bootstarp4を使っているのですが、formでの送信の方法が違っていたりするのでしょうか?
別サイトで質問したのですが、なかなか回答が付きません。
よろしくお願いします。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%><!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/png" href="images/favicon.png">
<title>ジョイステ</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/blog-post.css" rel="stylesheet">
<!-- fontawesome-->
<link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css"
rel="stylesheet">
<!-- テキストエディタ「Quilljs」のライブラリ -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css"
rel="stylesheet">
<link href="https://cdn.quilljs.com/1.3.6/quill.bubble.css"
rel="stylesheet">
<!-- Quillカスタマイズjs -->
<script type="text/javascript" src="js\quillcustom.js"></script>
</head>
<body style="background-color: #f5f5f5; padding-top: 7%;">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top"
style="background-color: #55c500;">
<div class="container">
<a class="navbar-brand" href="#"><img src="images/logo.png"
alt="" class="img-fluid h-25 w-25"><img
src="images/joystekun.png" alt="" class="img-fluid"
style="width: 10%; height: 10%;"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarResponsive" aria-controls="navbarResponsive"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active"><a class="nav-link display-5"
href="loginhome.jsp">Home <span class="sr-only">(current)</span>
</a></li>
<li class="nav-item active"><a class="nav-link display-5"
href="mypage.jsp">MyPage <span class="sr-only">(current)</span>
</a></li>
<li class="nav-item disabled"><a class="nav-link display-5"
href="post.jsp">Post <span class="sr-only">(current)</span>
</a></li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container pb-5">
<div class="row">
<!-- Post Content Column -->
<div class="col-lg-8 pb-5">
<!-- Title -->
<h1 class="mt-4">
<i class="fas fa-edit"></i>投稿画面
</h1>
<!-- Post Content -->
<form action="PreviewServlet" method="POST"
enctype="multipart/form-data">
<div class="form-group">
<label>タイトル</label> <input class="form-control" placeholder="タイトル"
type="text" name="title" size="50">
</div>
<!-- Category -->
<p>カテゴリー</p>
<div class="d-inline-flex p-2 bd-highlight">
<div class="row">
<div class="col-xs-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">☞</span>
</div>
<input type="text" name="category1" class="form-control"
aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-default" list="category"
placeholder="カテゴリーを選択">
<datalist id="category">
<option value="体づくり"></option>
<option value="料理"></option>
<option value="DIY"></option>
<option value="ゲーム"></option>
<option value="音楽"></option>
<option value="読書"></option>
</datalist>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">☞</span>
</div>
<input type="text" name="category2" class="form-control"
aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-default" list="category"
placeholder="カテゴリーを選択">
<datalist id="category">
<option value="体づくり"></option>
<option value="料理"></option>
<option value="DIY"></option>
<option value="ゲーム"></option>
<option value="音楽"></option>
<option value="読書"></option>
</datalist>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">☞</span>
</div>
<input type="text" name="category3" class="form-control"
aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-default" list="category"
placeholder="カテゴリーを選択">
<datalist id="category">
<option value="体づくり"></option>
<option value="料理"></option>
<option value="DIY"></option>
<option value="ゲーム"></option>
<option value="音楽"></option>
<option value="読書"></option>
</datalist>
</div>
</div>
</div>
</div>
<!-- img -->
<div class="form-group">
<label for="exampleFormControlFile1">イメージ</label> <input
type="text" name="image" class="form-control-file"
id="exampleFormControlFile1">
</div>
<!-- editor-body -->
<div class="form-group">
<label>投稿内容</label>
<textarea name="content" class="form-control"
id="exampleFormControlTextarea1" rows="30"></textarea>
</div>
<!-- editor-footer -->
<div class="button">
<button class="btn btn-primary editorSubmit_submitBtn"
tabindex="12" type="submit" style="background-color: #adff2f;">
<span class="editorSubmit_submitBtnLabel active"> <i
class="fa fa-upload"> </i>プレビュー
</span>
</button>
</div>
</form>
</div>
<!-- Sidebar Widgets Column -->
<div class="col-md-4">
<!-- Search Widget -->
<div class="card my-4">
<h5 class="card-header">検索</h5>
<div class="card-body">
<div class="input-group">
<input type="text" class="form-control" placeholder="記事タイトルを入力">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</div>
</div>
<!-- User menu Widget -->
<div class="card my-4">
<h5 class="card-header">ユーザーメニュー</h5>
<div class="card-body">
<p>
<i class="far fa-edit"></i><a href="post.jsp">日記投稿</a>
</p>
<p>
<i class="fas fa-users-cog"></i><a href="userChange.jsp">ユーザー情報変更</a>
</p>
<p>
<i class="fas fa-sign-out-alt"></i><a href="home.jsp">ログアウト</a>
</p>
</div>
</div>
<!-- User info Widget -->
<div class="card my-4">
<h5 class="card-header">ユーザー情報</h5>
<div class="card-body">
<div class="row">
<div class="col-12 col-lg-8 col-md-6">
<h3 class="mb-0 text-truncated">ID:12345</h3>
<h3 class="mb-0 text-truncated">JAVA山JAVA郎</h3>
<p class="mb-0 text-truncated">
<i class="fa fa-envelope" aria-hidden="true"></i>メールアドレス
</p>
<p>私はカレーが好きです。</p>
<p>
<span class="badge badge-info tags">筋トレ</span> <span
class="badge badge-info tags">ヨガ</span> <span
class="badge badge-info tags">DIY</span>
</p>
</div>
<div class="col-12 col-lg-4 col-md-6 text-center">
<img
src="C:\Users\Owner\Documents\aグループ開発TNT\モックアップ構成\images\tag2.jpg"
alt="" class="mx-auto rounded-circle img-fluid">
</div>
<div class="col-12 col-lg-4">
<button class="btn btn-block btn-outline-success">
<span class="fa fa-plus-circle"></span> 日記
</button>
</div>
<div class="col-12 col-lg-4">
<button class="btn btn-outline-info btn-block">
<span class="fa fa-user"></span>タグ
</button>
</div>
<div class="col-12 col-lg-4">
<button type="button" class="btn btn-outline-primary btn-block">
<span class="fa fa-search"></span> 検索
</button>
</div>
<!--/col-->
</div>
<!--/row-->
</div>
</div>
</div>
<!-- /.row -->
</div>
</div>
<!-- /.container -->
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Copyright © Your
Website 2019</p>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous">
</script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous">
</script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous">
</script>
<script>
// 通常のエディタ
var quill_1 = QuillEditorMake("quill-editor_1")
// 通常のエディタ(文章あり)
var quill_2 = QuillUpdateEditorMake("quill-editor_2",
quill_1.getContent)
// 編集不可エディタ(記事表示用)
var quill_3 = QuillPageMake("quill-editor_1", quill_1.getContent)
</script>
</body>
</html>
package controller.post;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/PreviewServlet")
public class PreviewServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String title = req.getParameter("title");
String content = req.getParameter("content");
String image = req.getParameter("image");
String category1 = req.getParameter("category1");
String category2 = req.getParameter("category2");
String category3 = req.getParameter("category3");
Date dateNow = new Date();
String date = String.valueOf(dateNow);
List<String> list = new ArrayList<String>();
list.add(title);
list.add(content);
list.add(image);
list.add(category1);
list.add(category2);
list.add(category3);
list.add(date);
HttpSession session = req.getSession();
session.setAttribute("DATALIST", list);
String move = "postresult.jsp";
req.getRequestDispatcher(move).forward(req, resp);
}
}