java - Servlet doesn't execute response.sendRedirect(addressPath); , but does execute response.sendRedirect() without path -


consider following hierarchy :

enter image description here

when send redirect :

    response.sendredirect("error404.jsp");    // no path here !!! 

i reach page error404.jsp .

but when use path :

    string addresspath = "/web-inf/results/admin/adminpage.jsp";     response.sendredirect(addresspath);   // path !!! 

i 404 :

http status 404 -  type status report  message  description requested resource not available.  apache tomcat/7.0.50 

what doing wrong here ?

much appreciated !

see javadoc

this method can accept relative urls;the servlet container must convert relative url absolute url before sending response client. if location relative without leading '/' container interprets relative current request uri. if location relative leading '/' container interprets relative servlet container root. if location relative 2 leading '/' container interprets network-path reference (see rfc 3986: uniform resource identifier (uri): generic syntax, section 4.2 "relative reference").

note argument not path within servlet context requestdispatcher use, url used in location header of 302 response.

so this

string addresspath = "/web-inf/results/admin/adminpage.jsp"; response.sendredirect(addresspath);   // path !!! 

will transformed 302 response header

location: http://whateverhost.com/web-inf/results/admin/adminpage.jsp 

which don't have handler for, 404.

on other hand, this

response.sendredirect("error404.jsp");    // no path here !!! 

becomes

location: http://whateverhost.com/context-path/error404.jsp 

since error404.jsp outside web-inf, accessible , therefore rendered jsp servlet , returned response.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -