首页 > 编程语言 > 详细

Java servlet example - HttpServletRequest, getPathInfo, and getRequestURI

时间:2015-06-18 21:37:28      阅读:325      评论:0      收藏:0      [点我收藏+]

 

Working on tag support for this blog, I‘ve cut a little sample code out of a Java servlet, and I‘m showing it below. I was looking at the HttpServletRequest, and was curious about the difference betweenrequest.getPathInfo()request.getPathTranslated(), and request.getRequestURI(), so I created this demo code. Here‘s the example code from the servlet:

String pathInfo = request.getPathInfo();
String pathTrans = request.getPathTranslated();
String uri = request.getRequestURI();

System.err.println("pathInfo:  " + pathInfo);
System.err.println("pathTrans: " + pathTrans);
System.err.println("uri:       " + uri);

  

And here‘s the sample output from the servlet, running under Tomcat on my MacBook Pro:

pathInfo:  /java+mac+foo
pathTrans: /Users/al/tomcat-4.1.31/webapps/blog/tag/java+mac+foo
uri:       /blog/tag/java+mac+foo

  

I forgot to mention, the URL I hit to generate this output was http://localhost:8080/blog/tag/java+mac+foo

Java servlet example - HttpServletRequest, getPathInfo, and getRequestURI

原文:http://www.cnblogs.com/hephec/p/4586848.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!