Title: Servlet??(2) ???????????Web???
1Servlet??(2) ???????????Web???
- ????? ????
- s00395rk_at_sfc.keio.ac.jp
2???????
- Web???????????
- ???????????????????
- ??????????????
- ??????????????????????????????????
- Web???????????????()v
3???????(1)
- Web???????????
- HTTP???????????????????????
- ???????????????????
- ??????????????
- Web???????????????()v
4???????(2)
- Web???????????
- ???????????????????
- Web????Web??????????????????
- ??????????????????
- ??????????????
- Web???????????????()v
5???????(3)
- Web???????????
- ???????????????????
- ??????????????
- ?????????Java??????
- HTTP???????????????????HTTP???????????
- Web???????????????()v
6???????(4)
- Web???????????
- ???????????????????
- ??????????????
- Web???????????????()v
- Web?????????????
- Web?????????????
- ???Servlet????????????
- Web????????????!!!!
7?????
- ??????????????????????????????????????????????
- HTML?????????Servlet???????????????????????????Web
???????
8Servlet?????????(1)??????????
Web Browser
Tomcat
???
TimeServlet.class
9Servlet?????????(2)???????????
Web Application Server (Tomcat)
Web Browser
Web Server
Servlet Engine
TimeServlet.class
10Servlet?????????(3)
- ?????Web????????HTTP???????????
- Web??????????????????????????????????
- ?????????????????????????????????????????????????
- ??????????????????????????????????????????????????
???Web??????? - Web?????????????????????????
11Web?????????
A.???????????????????
??????????????!
12???Web????????
- ???Web????
- ?????????????????
- ?????????????????????????
- ??????Web????
- ???????????????????????????????????????????
- ???????????
13?????????Web????
14?????-??????Web???
Web????? ??????
index.html
15??????-??????Web???
???
???
????
web.xml???????????
??
web.xml?????????????????????????????????????????
????????!
16?????Servlet?????????
ApplicationServer
WebBrowser
toukou.html
???
ToukouServlet.class
17HTTP GET?HTTP POST
- ??????GET?POST????????????????????
18????????
19??????????????
ApplicationServer
WebBrowser
toukou.html
???
20??????????HTML????
..ltform name"form1" method"post
action"../servlet/ToukouServlet"gt ltfont
size1gt???lt/fontgt ltinput type"text"
size"20" name"contributor"gt ltfont
size"1"gt????lt/fontgt ltinput type"text"
size"50" name"title" gt ltfont size"1"gt??lt/font
gt lttextarea namecontent" cols"50"
rows"10"gt lt/textareagt ltinput typesubmit
namesubmit value??gt ltinput typereset
namereset value????gt lt/formgt..
21HTML???????(1)?????????
- ltform nameform1 methodpost
- action../servlet/ToukouServletgt
???????????????????(??)? ??????????????????(??)?
lt/formgt
22HTML???????(2)???????????????
ltinput type " text " size " 20 " name "
contributor " gt
lttextarea name " content " cols"50"
rows"10"gtlt/textareagt
23HTML???????(3)???????????????
ltinput type " submit " name " submit " value
"??" gt
ltinput type " reset " name " reset " value
"????" gt
24???????
HTTP GET??????????????????????? GET
./servlet/ToukouServlet?contributor???titleweb.
xml HTTP/1.1 ??????????URL????????????? ????HTTP
POST??????????
25???????? ??
?????
26????????
27??????????????
ApplicationServer
WebBrowser
???
ToukouServlet.class
28???????????
POST ./servlet/ToukouServlet HTTP/1.1 Length 64
contributor???titleweb.xml????? question
web.xml?????????????
??? ???????????(Tomcat)? ???????????????????
29??????????
- ?????(Key)????(Value)????????????
- ????????
- ????????????name?Key
- ??????????????Value
contributor ??? title
web.xml????? name web.xml?????????
30??????2????
ToukouServlet.java
?????? ??????
????????????? (????????)
HTML????? ??
?????
31public class ToukouServlet extends HttpServlet
/ doPost() ??????POST???????????
?????????????????????????? / public void
doPost(HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException
//??????????????????? /
HTML????????????????????
??????????????????????????? /
request.setCharacterEncoding("Shift_JIS")
/ ???????????????????????????
???????????????????????? / String
contributor request.getParameter("contributor")
//??contributor?????????????contributor????
String title request.getParameter("title")
//??title?????????????title???? String
content request.getParameter("content")
//??content?????????????content????
//????????????????
//???????????????????
//??????????????????????????????
response.setContentType("text/htmlcharsetShift_J
IS") //??????????PrintWriter??????
PrintWriter out response.getWriter()
//HTML?????????????????/
out.println("lthtmlgt") out.println("ltbody
bgcolor\"33CCFF\" text\"000000\"gt")
out.println("lthrgt") //???????????????
out.print("ltbgtltfont size4gtltpgt"contributor"?????
lt/fontgtlt/bgt") out.print("(????" new
java.util.Date() ")ltBR/gtlt/pgt")
//?????????? out.println("ltpgtltfont size5
color\"00339\"gtlt/fontgtltfont size5gt"title"lt/fo
ntgtlt/pgtlthr/gt") //???????
out.println(content"lt/pgtlthr/gt")
out.println("lt/bodygt") out.println("lt/htmlgt")
//????????????????
?????? ??????
HTML????? ??
32?????????????????????????
- HTML????????????????????
- ???????????????????????????
request.setCharacterEncoding("Shift_JIS")
33??????????
- ???????????????????????????
- ?????????????????????????????
String contributor request.getParameter("contrib
utor") //??contributor?????????????contributor???
? String type request.getParameter("type") //??
type?????????????type???? String content
request.getParameter(content") //??content??????
???????content????
34???????????
String contributor request.getParameter("contrib
utor")
Key
Value
contributor ??? title
web.xml????? name web.xml?????????
???
35HTML??????????????????????
- ??????????????
- ????????????????
response.setContentType("text/htmlcharsetShift_J
IS")
36HTML???????
//HTML?????????????????/ out.println("lthtmlgt")
out.println("ltbody bgcolor\"33CCFF\"
text\"000000\"gt") out.println("lthrgt") //??????
????????? out.print(ltbgtltfont size4gtltpgtcontribu
tor?????lt/fontgtlt/bgt") out.print("(????" new
java.util.Date() ")ltBR/gtlt/pgt") //?????????? out
.println("ltpgtltfont size5gt"title"lt/fontgtlt/pgtlthr/
gt") //??????? out.println(content"lt/pgtlthr/gt") o
ut.println("lt/bodygt") out.println("lt/htmlgt") //
????????????????
??????????????????!?\???????
37???????? ??
?????
38????????
???????????????????????????????????????? (????????
???????????????)
???????????????????? HTML?????????????????????????
??????????????? (???Web????????????????)
39Web??????(??)
- Web??????????????????????????????
- (Web???????????????????????????)
GimonKaiketu-Web
WEB-INF
classes
ToukouServlet.class
lib
web.xml
toukou.html
html
index.html
40????HTML??????
- text-????????
- textarea-???????
- radio-??????
- checkbox-????????
- select-???????
- submit-?????
- reset-???????
- ???password?hidden
????WWW???????HTML???????????
http//tohoho.wakusei.ne.jp/www.htm
41???????!!!
- ?????????Web?????????????
- ???????????????????????
- ????o(-)o