Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First let's clear some vocabulary:</p> <ul> <li><p><code>error.jsp</code> and <code>./../error.jsp</code> are examples of <em>relative</em> paths</p></li> <li><p><code>/page01.jsp</code> and <code>/app/page.html</code> are examples of <em>absolute</em> paths</p></li> </ul> <p>Back to your question. When using <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/RequestDispatcher.html" rel="noreferrer"><code>RequestDispatcher</code></a> by calling <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)" rel="noreferrer"><code>ServletContext.getRequestDispatcher(String)</code></a> you must always forward within your web application and leading slash is necessary (bold mine):</p> <blockquote> <p>The pathname must begin with a <code>/</code> and is interpreted as relative to the <strong>current context root</strong>.</p> </blockquote> <p>So when you forward to <code>/page01.jsp</code> it is interpreted as: <code>/your_context/page01.jsp</code> where <code>your_context</code> is the name of your web application.</p> <p>However when you send redirect to the <code>/error.jsp</code> path, servlet container simply sends that address back in 302 response to the browser. Now the browser interprets it as follows: please redirect to <code>/error.jsp</code>, an absolute path in the current server. So even if the browser was pointing to <code>http://example.com/foo/bar/servlet</code>, this response redirects to <code>http://example.com/error.jsp</code>.</p> <p>It's much different, however, if you simply redirect to <code>error.jsp</code> the browser behaves differently. It interprets it as file in current directory. So <code>http://example.com/foo/bar/servlet</code> will be redirected to <code>http://example.com/foo/bar/error.jsp</code>. And this is what you see.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload