Java servlet example-httpservletrequest, GetPathInfo, and Getrequesturi

Source: Internet
Author: User

Working on the 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 is curious about the difference between request.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 Servlets, running under Tomcat on my MacBook Pro:

PathInfo:  /java+mac+foopathtrans:/users/al/tomcat-4.1.31/webapps/blog/tag/java+mac+foouri:       /blog/tag/ Java+mac+foo

  

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

Java servlet example-httpservletrequest, GetPathInfo, and Getrequesturi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.