#02:標準アクションタグ1 - include, param
このチャプターでは、標準アクションタグのincludeとparamについて学習します。
【header.jsp】<header>
<div>MySite</div>
<nav>
<ul>
<li><a href="#">A</a></li>
<li><a href="#">B</a></li>
<li><a href="#">C</a></li>
</ul>
</nav>
</header>
【style.css】@charset "utf-8";
body {
margin: 0;
background-color: #f9fafb;
font-family: sans-serif;
}
.page-background {
display: flex;
justify-content: center;
padding: 2rem 1rem;
box-sizing: border-box;
}
.form-container {
width: 100%;
max-width: 512px;
background-color: white;
border-radius: 0.75rem;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
padding: 1.5rem;
}
h1 {
font-size: 1.5rem;
font-weight: bold;
text-align: center;
margin-top: 0;
margin-bottom: 2rem;
}
.input-group {
margin-bottom: 1.5rem;
}
label {
display: block;
font-size: 0.875rem;
color: #374151;
margin-bottom: 0.5rem;
font-weight: 500;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 0.75rem 1rem;
border: 1px solid #d1d5db;
border-radius: 0.5rem;
box-sizing: border-box;
font-size: 1rem;
transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus,
input[type="password"]:focus {
outline: none;
border-color: #3b82f6;
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}
button {
background-color: #3b82f6;
color: white;
font-weight: bold;
padding: 0.5rem 1.5rem;
border: none;
border-radius: 9999px;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #2563eb;
}
.form-actions {
display: flex;
justify-content: flex-end;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid #f3f4f6;
}
header {
background-color: white;
padding: 0 2rem;
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
width: 100%;
box-sizing: border-box;
}
header .site-title {
font-size: 1.5rem;
font-weight: bold;
color: #111827;
}
header nav ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
gap: 1.5rem;
}
header nav a {
text-decoration: none;
color: #4b5563;
font-weight: 500;
transition: color 0.2s;
}
header nav a:hover {
color: #3b82f6;
}
【link】<link rel="stylesheet" href="css/style.css" type="text/css">
【login-input.jsp】<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>ログインフォーム</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<jsp:include page="header.jsp">
<jsp:param name="site" value="paiza" />
</jsp:include>
<div class="page-background">
<div class="form-container">
<h1>ログイン</h1>
<form action="/learning/login" method="POST">
<div class="input-group">
<label for="user-id">ユーザーID</label>
<input type="text" id="user-id" name="user-id" required>
</div>
<div class="input-group">
<label for="password">パスワード</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-actions">
<button type="submit">ログイン</button>
</div>
</form>
</div>
</div>
</body>
</html>
【login-result.jsp】<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>ログイン</title>
</head>
<body>
<jsp:include page="header.jsp" />
<h1>ログイン成功</h1>
</body>
</html>
【header.jsp】 <header>
<div><%= request.getParameter("site") %></div>
<nav>
<ul>
<li><a href="#">A</a></li>
<li><a href="#">B</a></li>
<li><a href="#">C</a></li>
</ul>
</nav>
</header>
新・HTML/CSS入門編
https://paiza.jp/works/html-css/new-primer
新・Java入門編
https://paiza.jp/works/java/new-primer