質問編集履歴

1

サーブレットのコードを載せました。

2019/09/06 03:26

投稿

humu
humu

スコア5

test CHANGED
File without changes
test CHANGED
@@ -46,6 +46,144 @@
46
46
 
47
47
  ```
48
48
 
49
+ ```Java
50
+
51
+ import java.io.*;
52
+
53
+ import java.io.IOException;
54
+
55
+ import javax.servlet.RequestDispatcher;
56
+
57
+ import javax.servlet.ServletContext;
58
+
59
+ import javax.servlet.ServletException;
60
+
61
+ import javax.servlet.annotation.WebServlet;
62
+
63
+ import javax.servlet.http.HttpServlet;
64
+
65
+ import javax.servlet.http.HttpServletRequest;
66
+
67
+ import javax.servlet.http.HttpServletResponse;
68
+
69
+
70
+
71
+ import model.Logic1;
72
+
73
+ import model.Beans;
74
+
75
+
76
+
77
+ @WebServlet("/Servlet1")
78
+
79
+
80
+
81
+ public class Servlet1 extends HttpServlet{
82
+
83
+ private static final long serialVersionUID = 1L;
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ protected void doGet(HttpServletRequest request,
92
+
93
+ HttpServletResponse response)
94
+
95
+ throws ServletException,IOException{
96
+
97
+
98
+
99
+
100
+
101
+ ServletContext context = request.getServletContext();
102
+
103
+ RequestDispatcher rd = context.getRequestDispatcher("/top.jsp");
104
+
105
+ rd.forward(request,response);
106
+
107
+
108
+
109
+
110
+
111
+ //String disp = "/top.jsp";
112
+
113
+ //RequestDispatcher dispatch = request.getRequestDispatcher(disp);
114
+
115
+
116
+
117
+ //dispatch.forward(request, response);
118
+
119
+
120
+
121
+ }
122
+
123
+
124
+
125
+ protected void doPost(HttpServletRequest request,
126
+
127
+ HttpServletResponse response)
128
+
129
+ throws ServletException,IOException{
130
+
131
+
132
+
133
+
134
+
135
+ String x = request.getParameter("x");
136
+
137
+ String y = request.getParameter("y");
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ Beans be = new Beans();
146
+
147
+ be.setX (Integer.parseInt(x));
148
+
149
+ be.setY (Integer.parseInt(y));
150
+
151
+
152
+
153
+ ;
154
+
155
+
156
+
157
+ Logic1 lg = new Logic1();
158
+
159
+ lg.execute(be);
160
+
161
+
162
+
163
+ request.setAttribute("be",be);
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+ String disp = "/result.jsp";
174
+
175
+ RequestDispatcher dispatch = request.getRequestDispatcher(disp);
176
+
177
+
178
+
179
+ dispatch.forward(request, response);
180
+
181
+ }
182
+
183
+ }
184
+
185
+ ```
186
+
49
187
 
50
188
 
51
189
  ファイル構成は