81,094
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Demo.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="/Upload/TestServlet" method="post">
text: <input type="text" name="username" /><br>
password:<input type="password" name="psw" /><br>
checkbox:<br>
favorite1 <input type="checkbox" name="favorites" value="dance"/><br>
favorite2 <input type="checkbox" name="favorites" value="football"/><br>
favorite3 <input type="checkbox" name="favorites" value="kiss"/><br>
select: <select name="selectKey">
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select>
<br>
<input type="submit" value="post"/>
</form>
</body>
</html>
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse res) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse arg1)
throws ServletException, IOException {
ServletInputStream input = request.getInputStream();
byte [] buffer = new byte[256];
File file = new File("C:\\http","http.txt");
FileOutputStream outputFile = new FileOutputStream(file);
if(!file.exists()) {
file.mkdir();
}
int length = input.read(buffer,0, buffer.length);
while(length > 0){
outputFile.write(buffer,0,buffer.length);
outputFile.flush();
length = input.read(buffer,0, buffer.length);
}
outputFile.close();
input.close();
}
}