teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

プログラムを乗せた

2020/01/28 04:14

投稿

moyashikun
moyashikun

スコア11

title CHANGED
File without changes
body CHANGED
@@ -4,4 +4,121 @@
4
4
  test02.jspでどのようにURLを判断すればよろしいですか
5
5
  また"?id=foo"この部分の名称がわからないので教えてください
6
6
  Test02.javaではidの有無により処理を分岐しています
7
- idがある場合はtest02.jspでそのIDに対する中身を表示できているのですがIDがない場合は何も表示されなくて困ってます
7
+ idがある場合はtest02.jspでそのIDに対する中身を表示できているのですがIDがない場合は何も表示されなくて困ってます
8
+
9
+ ### 該当のソースコード
10
+
11
+ ```test01jsp
12
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
13
+ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
14
+ <!DOCTYPE html>
15
+ <html>
16
+ <head>
17
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
18
+ <script type="text/javascript" src="../js/dialog.js" charset="UTF-8">
19
+ </script>
20
+ <title>test</title>
21
+ <script type="text/javascript">
22
+ <!--
23
+
24
+ function deleteEmp(info.id) {
25
+ if(window.confirm('OK')){
26
+ location.href = "./Delete?id=" + id;
27
+ }
28
+ }
29
+
30
+ // -->
31
+ </script>
32
+
33
+ </head>
34
+ <body>
35
+ <a href="./Register">登録</a><br>
36
+ <h1>一覧</h1>
37
+ <table border="1">
38
+ <tr><th>No</th><th>会社名</th><th>社員名</th><th>社員ID</th><th>性別</th><th>勤務形態</th><th>詳細</th><th>削除</th></tr>
39
+ <c:forEach var="info" items="${en}" >
40
+ <tr>
41
+ <td><c:out value="${info.id}" /></td>
42
+ <td><a href="./Test02?ed=${info.id}">中身</a></td>
43
+ <td><p><a onClick="deleteEmp('${info.id}')">削除</a></p></td>
44
+ </tr>
45
+ </c:forEach>
46
+ </table>
47
+ </body>
48
+ </html>
49
+ ```
50
+
51
+ ```test02jsp
52
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
53
+ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
54
+ <!DOCTYPE html>
55
+ <html>
56
+ <head>
57
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
58
+ <script type="text/javascript" src="../js/dialog.js" charset="UTF-8">
59
+ </script>
60
+ <title>Test</title>
61
+ <script type="text/javascript">
62
+ <!--
63
+
64
+ function register() {
65
+ if(window.confirm('登録')){
66
+ return true;
67
+ }
68
+ else{
69
+ return false;
70
+ }
71
+ }
72
+
73
+ // -->
74
+ </script>
75
+
76
+ </head>
77
+ <body>
78
+ <h1>Test</h1>
79
+ <p>詳細</p>
80
+ <form action = "./Test02" method = "post" onSubmit="return register()" >
81
+ <font color="red">tet1</font>
82
+ <c:forEach var="info" items="${en}" varStatus="status">
83
+ <font color="red">tet2</font>
84
+ <input type="hidden" name="empId" value="${info.id}" >
85
+ <font color="red">tet3</font>
86
+ <table border = 1>
87
+ <tr><td>name</td><td><input type = "text" name = "name" value="${info.name}" ></td></tr>
88
+ </table>
89
+ </c:forEach>
90
+ <input type = "submit" value = "toroku">
91
+ <a href="./Test01"> <button type="button">modoru</button></a><br>
92
+ </form>
93
+ </body>
94
+ </html>
95
+ ```
96
+
97
+ ```Test02java
98
+ @WebServlet(name = "Test02", urlPatterns = {"/Register"})
99
+ public class Register extends HttpServlet {
100
+ private static final long serialVersionUID = 1L;
101
+
102
+
103
+ @Override
104
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
105
+ HttpSession session = request.getSession();
106
+ request.setCharacterEncoding("UTF-8");
107
+ if(request.getParameter("eid") != null){
108
+ int id = Integer.parseInt(request.getParameter("id"));
109
+ Dao dao = new Dao();
110
+ ArrayList<Info> Info = dao.selectid(id);
111
+ request.setAttribute("en", Info);
112
+ }
113
+
114
+
115
+ request.getRequestDispatcher("/WEB-INF/jsp/test02.jsp").forward(request, response);
116
+ }
117
+
118
+ @Override
119
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
120
+ //省略
121
+ }
122
+
123
+ }
124
+ ```