質問編集履歴

1

web.xmlとjavaのコードを追記致しました

2020/03/18 03:20

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,155 @@
21
21
  でも8080だとEclipse上でTomcatを起動できません。
22
22
 
23
23
  どうすればよいのやら。。。どなたかお助けください!!!
24
+
25
+
26
+
27
+ 【追記】
28
+
29
+ ★web.xml
30
+
31
+ ```
32
+
33
+ <?xml version="1.0" encoding="UTF-8"?>
34
+
35
+ <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
36
+
37
+ <servlet>
38
+
39
+ <servlet-name>SelfIntroduction</servlet-name>
40
+
41
+ <servlet-class>work.SelfIntroduction</servlet-class>
42
+
43
+ </servlet>
44
+
45
+ <servlet-mapping>
46
+
47
+ <servlet-name>SelfIntroduction</servlet-name>
48
+
49
+ <url-pattern>/SelfIntroduction</url-pattern>
50
+
51
+ </servlet-mapping>
52
+
53
+ </web-app>
54
+
55
+ ```
56
+
57
+
58
+
59
+ ★Javaコード
60
+
61
+ ```Java
62
+
63
+ package work;
64
+
65
+
66
+
67
+ import java.io.IOException;
68
+
69
+ import java.io.PrintWriter;
70
+
71
+
72
+
73
+ import javax.servlet.ServletException;
74
+
75
+ import javax.servlet.http.HttpServlet;
76
+
77
+ import javax.servlet.http.HttpServletRequest;
78
+
79
+ import javax.servlet.http.HttpServletResponse;
80
+
81
+
82
+
83
+ public class SelfIntroduction extends HttpServlet {
84
+
85
+
86
+
87
+ private static final long serialVersionUID = 1L;
88
+
89
+
90
+
91
+ public SelfIntroduction() {
92
+
93
+ super();
94
+
95
+ }
96
+
97
+
98
+
99
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
100
+
101
+ throws ServletException, IOException {
102
+
103
+
104
+
105
+ //レスポンス(出力データ)の文字コードを設定
106
+
107
+ response.setContentType("text/html;charset=UTF-8"); //文字コードをUTF-8で設定
108
+
109
+
110
+
111
+ //出力用のストリームの取得
112
+
113
+ PrintWriter out = response.getWriter();
114
+
115
+
116
+
117
+ //HTML文書の出力
118
+
119
+ out.println( "<html> " );
120
+
121
+ out.println( "<head> " );
122
+
123
+ out.println( " <title>自己紹介</title> " );
124
+
125
+ out.println( "</head> " );
126
+
127
+ out.println( "<body> " );
128
+
129
+ out.println( " <h1>自己紹介ページ</h1> " );
130
+
131
+ out.println( " <h2>MOCO</h2> " );
132
+
133
+ out.println( " <img src=\"pictures/picture01_500x350.jpg\" width=\"250\" height=\"175\"> " );
134
+
135
+ out.println( " <hr width = \"400\" align = \"left\"> " );
136
+
137
+ out.println( " <p>・誕生   :2013年</p> " );
138
+
139
+ out.println( " <p>・出身   :台湾</p> " );
140
+
141
+ out.println( " <p>・職業   :就活犬(接客、メンタルケア)</p> " );
142
+
143
+ out.println( " <p>・好きな数字:「1(ONE)」</p> " );
144
+
145
+ out.println( " <p>・家族   :岡本</p> " );
146
+
147
+ out.println( " <img src=\"pictures/picture02_300x200.jpg\" width=\"150\" height=\"100\"> " );
148
+
149
+ out.println( "</body> " );
150
+
151
+ out.println( "</html> " );
152
+
153
+
154
+
155
+ }
156
+
157
+
158
+
159
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
160
+
161
+ throws ServletException, IOException {
162
+
163
+
164
+
165
+ doGet(request, response);
166
+
167
+
168
+
169
+ }
170
+
171
+
172
+
173
+ }
174
+
175
+ ```