티스토리 뷰
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>babyServlet</display-name>
<welcome-file-list>
</welcome-file-list>
<servlet>
<servlet-name>HiServlet(/파일이름)</servlet-name>
<servlet-class>a.b.c.HiServlet(/패키지가 포함된 파일이름)</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HiServlet(/파일이름)</servlet-name>
<url-pattern>/aaaa(별명= 새로운 경로)</url-pattern>
</servlet-mapping>
</web-app>
|
web.xml에서 다른페이지로 이동할 경로 설정하기
-------------------------------------------
FormHtml.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
request.setCharacterEncoding("EUC-KR");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title colspan = "16" align = "center">주문 양식</title>
<style type = "text/css"></style>
</head>
<body>
<%
Object obj = request.getAttribute("aList");//오브젝트로 받아옴
System.out.println("obj >>> : " + obj);
out.print("obj >>> : " + obj);
if(obj != null){
ArrayList<String> aList = (ArrayList<String>)obj;
out.println(formName);
out.println(formCountry);
out.println(formDeliveryMethod);
out.println(formAddress);
out.println(formInsruction);
out.println(formCatalogRequest);
%>
<center>
<table border = "1" align = "center">
<tr>
<td colspan = "16" align = "center"><h3>주문양식</h3></td>
</tr>
<tr>
<td align = "center">이름</td>
<td><input size ="10" value=<%=formName%>></td>
</tr>
<tr>
<td align = "center">주소</td>
<td><textarea cols ="30" rows = "10" ><%=formAddress%></textarea></td>
</tr>
<tr>
<td align = "center">국가</td>
<td><textarea ><%=formCountry%></textarea>
</td>
</tr>
<tr>
<td align = "center">배송 방법</td>
<td>
<input value=<%=formDeliveryMethod%>>
</td>
</tr>
<tr>
<td align = "center">배송유의사항</td>
<td><textarea cols ="30" rows = "10 "><%=formInsruction%></textarea></td>
</tr>
<tr>
<td colspan = "2" align = "center">제품 카탈로그 요청 여부
<input value=<%=formCatalogRequest%>></td>
</tr>
</table>
<tr><td><h3>Debug Info</h3></td>
</tr>
<tr>
<%
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("address", formAddress);
hm.put("deliveryMethod", formDeliveryMethod);
hm.put("name",formName);
hm.put("catalogRequest" ,formCatalogRequest);
hm.put("insruction",formInsruction);
hm.put("formCountry",formCountry);
Iterator keys = hm.keySet().iterator();
while (keys.hasNext()){
%>
<td><%=key%> : <%=value%><br></td>
</tr>
<%
}
%>
</center>
<%
}else{
out.print("정보의 길이가 없음");
}
}else{
out.print("들어온 정보 없음");
}
%>
</body>
</html>
|
FormServlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package bitcamp.java142.ch6;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
/**
* Servlet implementation class TodayMenu
*/
@WebServlet("/FormServlet")
public class FormServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("EUC-KR");
response.setContentType("text/html;charset=EUC-KR");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>배송결과</title></head>");
//배열length / 어레이리스트 size
String formName = request.getParameter("name");
String formAddress = request.getParameter("address");
String formCountry = request.getParameter("country");
String formDeliveryMethod = request.getParameter("deliveryMethod");
String[] formInsructions = request.getParameterValues("insruction");
String formInsruction = "";
int instructionLength = formInsructions.length;
for(int i=0 ; i<instructionLength; i++){
formInsruction = formInsruction + formInsructions[i];
formInsruction = formInsruction + "<br>";
}
String formCatalogRequest = request.getParameter("catalogRequest");
if(formCatalogRequest == null){
formCatalogRequest = "아니오";
}else if(formCatalogRequest.equals("예")){
formCatalogRequest = "예";
}
ArrayList<String> aList = new ArrayList<String>();
aList.add(formName);
aList.add(formAddress);
aList.add(formCountry);
aList.add(formDeliveryMethod);
aList.add(formInsruction);
aList.add(formCatalogRequest);
request.setAttribute("aList", aList);
RequestDispatcher rd = request.getRequestDispatcher("/jsp/FormJsp.jsp");
rd.forward(request, response);
}
}
|
FormJsp.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
request.setCharacterEncoding("EUC-KR");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title colspan = "16" align = "center">주문 양식</title>
<style type = "text/css"></style>
</head>
<body>
<%
Object obj = request.getAttribute("aList");//오브젝트로 받아옴
System.out.println("obj >>> : " + obj);
out.print("obj >>> : " + obj);
if(obj != null){
ArrayList<String> aList = (ArrayList<String>)obj;
out.println(formName);
out.println(formCountry);
out.println(formDeliveryMethod);
out.println(formAddress);
out.println(formInsruction);
out.println(formCatalogRequest);
%>
<center>
<table border = "1" align = "center">
<tr>
<td colspan = "16" align = "center"><h3>주문양식</h3></td>
</tr>
<tr>
<td align = "center">이름</td>
<td><input size ="10" value=<%=formName%>></td>
</tr>
<tr>
<td align = "center">주소</td>
<td><textarea cols ="30" rows = "10" ><%=formAddress%></textarea></td>
</tr>
<tr>
<td align = "center">국가</td>
<td><textarea ><%=formCountry%></textarea>
</td>
</tr>
<tr>
<td align = "center">배송 방법</td>
<td>
<input value=<%=formDeliveryMethod%>>
</td>
</tr>
<tr>
<td align = "center">배송유의사항</td>
<td><textarea cols ="30" rows = "10 "><%=formInsruction%></textarea></td>
</tr>
<tr>
<td colspan = "2" align = "center">제품 카탈로그 요청 여부
<input value=<%=formCatalogRequest%>></td>
</tr>
</table>
<tr><td><h3>Debug Info</h3></td>
</tr>
<tr>
<%
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("address", formAddress);
hm.put("deliveryMethod", formDeliveryMethod);
hm.put("name",formName);
hm.put("catalogRequest" ,formCatalogRequest);
hm.put("insruction",formInsruction);
hm.put("formCountry",formCountry);
Iterator keys = hm.keySet().iterator();
while (keys.hasNext()){
%>
<td><%=key%> : <%=value%><br></td>
</tr>
<%
}
%>
</center>
<%
}else{
out.print("정보의 길이가 없음");
}
}else{
out.print("들어온 정보 없음");
}
%>
</body>
</html>
|