URL处理问题

jacksoom 2017-02-12 10:41:57
tomcat8.0,报错Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
有一个这个url:http://localhost:8080/answer/?2|1
怎么获取?后面以|分隔符的数字,
...全文
447 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacksoom 2017-03-24
  • 打赏
  • 举报
回复
没贴上自己的tomcat版本,是我的问题.
jacksoom 2017-03-24
  • 打赏
  • 举报
回复
非常感谢各位的回答,一直忙着忘记回复各位, Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 有一个这个url:http://localhost:8080/answer/?2|1 当我输入这个http://localhost:8080/answer/?2|1并不会route到相应的位置并处理,而是直接报错url格式, 报错版本8.0.41,成功运行版本8.0.35(时间过长,版本记得不是非常清楚) 这个错误,我参考了各位的解法,但是最后当我更改了tomcat的版本之后,当我输入这个url的时候,就不会报这个错误,我觉得是因为这两个不同版本的server在url检查上有一些差别.
jiajing1990_ 2017-02-22
  • 打赏
  • 举报
回复
参考楼上回答
HerveyHall 2017-02-18
  • 打赏
  • 举报
回复
Servlet的实现如下:
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String[] query = request.getQueryString().split("\\|");
		response.getWriter().println(query.length > 1 ? query[1] : null);
	}
「已注销」 2017-02-18
  • 打赏
  • 举报
回复
引用 4 楼 it_junior 的回复:
用String类API的方法

String s = "http://localhost:8080/answer/?2|1";
System.out.println(s.substring(s.indexOf("|")+1));
好好学习,自己多思考,而不是直接上来就问
「已注销」 2017-02-18
  • 打赏
  • 举报
回复
用String类API的方法
淡定的峰哥 2017-02-14
  • 打赏
  • 举报
回复
url的问号后面的内容用url encoding一下即可
  • 打赏
  • 举报
回复
http://localhost:8080/answer/?par='2|1'
叶旅魂途 2017-02-12
  • 打赏
  • 举报
回复
暴力解决办法,得到ServletInputStream 输出接收到的所有数据

62,621

社区成员

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

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