<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sleepydisco &#187; reference</title>
	<atom:link href="http://www.sleepydisco.com/tag/reference/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sleepydisco.com</link>
	<description>A blog about technology, music, food and photography.</description>
	<lastBuildDate>Sun, 18 Apr 2010 20:53:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Documenting HttpServletRequest</title>
		<link>http://www.sleepydisco.com/programming/documenting-httpservletrequest</link>
		<comments>http://www.sleepydisco.com/programming/documenting-httpservletrequest#comments</comments>
		<pubDate>Sun, 20 Dec 2009 14:27:29 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[httpservletrequest]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://www.sleepydisco.com/?p=201</guid>
		<description><![CDATA[For such a core object the HttpServletRequest javadoc is a little lacking in the Examples Dept. when it comes to documented output. With various methods returning various parts of URLs, it&#8217;s often easy to pick the wrong one, so I thought I&#8217;d knock up a little table with the getters which trip me up sometimes.
This [...]]]></description>
			<content:encoded><![CDATA[<p>For such a core object the <a title="HttpServletRequest javadoc" href="http://java.sun.com/webservices/docs/1.6/api/javax/servlet/http/HttpServletRequest.html">HttpServletRequest javadoc</a> is a little lacking in the Examples Dept. when it comes to documented output. With various methods returning various parts of URLs, it&#8217;s often easy to pick the wrong one, so I thought I&#8217;d knock up a little table with the getters which trip me up sometimes.<span id="more-201"></span></p>
<p>This assumes a simple webapp, living on a server on the local machine, sitting under the context called &#8216;context&#8217;, responding to the URL:</p>
<pre>http://localhost:8080/context/hello/world?foo=bar</pre>
<table>
<thead>
<tr>
<th>Method</th>
<th>Response</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>getContextPath()</td>
<td>/context</td>
<td>The context part of the URL. Should be obvious.</td>
</tr>
<tr>
<td>getPathInfo()</td>
<td>/hello/world</td>
<td>The part of the URL after the context, but not including the query string.</td>
</tr>
<tr>
<td>getPathTranslated()</td>
<td>/Users/david/projects/java/hello-world-webapp/target/context/hello/world</td>
<td>Hrm. Sort of where this would be on the local filesystem, but not really.</td>
</tr>
<tr>
<td>getProtocol()</td>
<td>HTTP/1.1</td>
<td>This doesn&#8217;t produce anything verbatum from the URL, such as &#8216;http&#8217; or &#8216;https&#8217; or &#8216;ftp&#8217; or&#8230;</td>
</tr>
<tr>
<td>getQueryString()</td>
<td>foo=bar</td>
<td>Like it says, the query string.</td>
</tr>
<tr>
<td>getRequestURI()</td>
<td>/context/hello/world</td>
<td>Everything from but not including the port, up to but not including the query string.</td>
</tr>
<tr>
<td>getRequestURL()</td>
<td>http://localhost:8080/context/hello/world</td>
<td>This is a StringBuffer object, containing everything but the query string.</td>
</tr>
<tr>
<td>getServerName()</td>
<td>localhost</td>
<td>The server name as presented in the URL, not the hostname of the box.</td>
</tr>
<tr>
<td>getServerPort()</td>
<td>8080</td>
<td>As expected. Good, good.</td>
</tr>
<tr>
<td>getServletPath()</td>
<td></td>
<td>This is the path that the servlet is configured (e.g. in web.xml) to respond to relative to the context. It&#8217;ll be an empty-string if, as here, this is in response to a wildcard mapping &#8220;/*&#8221;.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.sleepydisco.com/programming/documenting-httpservletrequest/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
