(一)从底层透析文件上传的实现,此时并没有介入struts2
1、upload.jsp,在form中属性method默认为get,涉及文件上传时必须改为post,默认enctype="application/x-www-form-urlencoded" ,我们暂且不修改,看会有什么结果
1
<%@ page language="java" contentType="text/html; charset=GBK"
2
pageEncoding="GBK"%>
3
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4
<html>
5
<head>
6
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
7
<title>Insert title here</title>
8
</head>
9
<body>
10
<form action="result.jsp" method="post"
11
enctype="application/x-www-form-urlencoded">
12
Information:
13
<input type="text" name="info">
14
<br>
15
File:
16
<input type="file" name="file">
17
<br>
18
<input type="submit" name="submit" value=" submit ">
19
</form>
20
</body>
21
</html>
result.jsp
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

1
<%@ page language="java" contentType="text/html; charset=GBK"
2
pageEncoding="GBK"%>
3
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4
<html>
5
<head>
6
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
7
<title>Insert title here</title>
8
</head>
9
<body>
10
Information:<%=request.getParameter("info")%><br>
11
File:<%=request.getParameter("file")%><br>
12
</body>
13
</html>
结果:
2

3

4

5

6

7

8

9

10

11

12

13



2、修改result.jsp页面代码,输出读入的流












这个结果可以断定,文件的上传并没有成功,而仅仅是上传了文件的路径信息而已
3、把upload.jsp中form的enctype属性改为enctype="multipart/form-data"










说明文件上传是成功的。