最近在看http协议的东西,按道理我的ServletInputStream应该能读到全部的请求信息,请求行,状态行,
请求内容。但在servlet里面写到文本文件中只有request的请求参数。不得其解。请了解的帮忙看下哪里出问题了。下面是jsp代码。<%@ 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>servlet代码。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();
}
}
请求内容。但在servlet里面写到文本文件中只有request的请求参数。不得其解。请了解的帮忙看下哪里出问题了。下面是jsp代码。<%@ 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>servlet代码。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();
}
}
解决方案 »
- ext spring mvc 数据绑定问题咨询
- 新手请教,如何在获取radio的状态?
- 我学JAVA一年多了,J2EE的相关也已学了,现在该别人做个小项目
- 使用jsp实现word格式报表打印中的动态图象获取的难题!!
- 问过很多次 但是还没有解决 大家再近来看看阿 多谢了
- 不同分辨率显示的问题
- 在线等待!引用JSP文件怎么出空白页
- 为什么无法用getString()方法取text类型字段的数据,高分求救,分不够再加!
- 关于jsp与asp的一个问题
- 搭建spring+springmvc+hibernate遇到的问题,Error creating bean with name 'sessionFactory'
- sql2000关于update的一个问题
- jsp传递Servlet应该怎么写
username=csdn+&psw=123456&favorites=dance&selectKey=20 只有request的parameter参数,没有http请求的信息。
jsp上用的是表单,你提交到servlet肯定只有表单里面空间的名称和值
如果你要获得一个网页里面所有的代码,你可以用链接跳到一个servlet这样可以或得到。。