jsp中的getContentLength()长度计算问题

cxz_517 2018-02-05 10:42:45
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<body>
<%
int i = request.getContentLength();
out.println(i);
%>

<form action="" method="post">
<input type="text" name="s"/>
<input type="submit"/>
</form>
</body>
</html>


为什么输出的是2?
...全文
651 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wcwtitxu 2018-02-11
  • 打赏
  • 举报
回复
表单数据 默认按 x-www-form-urlencoded 格式提交 比如: "aaa=xxxxxxx&bbb=yyyyyyy&ccc=zzzzzzz" 你的 form 只有一个字段 s, 并且当 s 没有值的时候那么提交的就是 "s=" (Content-Length: 2)

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧