Servlet里取得url传来带有空格参数的问题

MQhong 2011-05-10 12:37:37
Test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'Test.jsp' starting page</title>

</head>

<body>

<a href="/Tessss/Test?id=abcbbb b" >fdfds</a>

</body>
</html>

package com.ser;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class Test extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html,charset=utf-8");

String id=request.getParameter("id");
System.out.println("id="+id);



}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.doGet(request, response);
}

}
为什么这个带有空格的URL我未做任何处理,后台能完整的打印出来啊?不是说URL要是带有空格参数的话要进行encode的吗为什么啊不解
...全文
261 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
MQhong 2011-05-10
  • 打赏
  • 举报
回复
。。。怎么都没人啊。。。
MQhong 2011-05-10
  • 打赏
  • 举报
回复
Test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'Test.jsp' starting page</title>

</head>

<body>

<a href="/Tessss/Test?id=abcbbb b" >fdfds</a>
</body>
</html>

package com.ser;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class Test extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html,charset=utf-8");

String id=request.getParameter("id");
System.out.println("id="+id);


//为什么后台能把abcbbb b这个带空格的完整打出来啊不解啊}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.doGet(request, response);
}

}
为什么这个带有空格的URL我未做任何处理,后台能完整的打印出来啊?不是说URL要是带有空格参数的话要进行encode的吗为什么啊不解
jumpheightway 2011-05-10
  • 打赏
  • 举报
回复
编码和提交方式有关系

81,094

社区成员

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

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