■実装するプログラムの仕様
2つのJSPファイルを使用して画面遷移を行う。
▼画面遷移イメージ図
「画面遷移はここをクリック!」ボタンを押下して、次の画面(JSPファイル)に遷移する。
![](https://anotools.com/wp-content/uploads/2022/04/image-2-1024x299.png)
▼URL
遷移元:
http://localhost:8080/JspServletSample/sample_jsp_from.jsp
遷移先:
http://localhost:8080/JspServletSample/hoge/sample_jsp_to.jsp
▼ディレクトリ階層イメージ
![](https://anotools.com/wp-content/uploads/2022/04/image-3-1024x833.png)
■画面仕様
▼sample_jsp_from.jsp
![](https://anotools.com/wp-content/uploads/2022/04/image-4.png)
①「画面遷移はここをクリック!」を押下し、「sample_jsp_to」へ遷移する。
▼sample_jsp_to.jsp
![](https://anotools.com/wp-content/uploads/2022/04/image-5.png)
①「画面遷移しました!」を表示する。
■サンプルソース
▼sample_jsp_from.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- 画面遷移先のURLを入力 --%>
<% String url_name = "http://localhost:8080/JspServletSample/hoge/sample_jsp_to.jsp"; %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>画面遷移前</title>
</head>
<body>
<a href=<%=url_name %>>画面遷移はここをクリック!</a>
</body>
</html>
▼sample_jsp_to.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% String message = "画面遷移しました!"; %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>画面遷移後</title>
</head>
<body>
<p><%=message %></p>
</body>
</html>
■実行結果
▼sample_jsp_from.jsp
![](https://anotools.com/wp-content/uploads/2022/04/image-6-1024x643.png)
「画面遷移はここをクリック!」を押下
▼sample_jsp_to.jsp
![](https://anotools.com/wp-content/uploads/2022/04/image-7-1024x717.png)