Why Java Servlet response.Redirect forces the browser to parse the requested HTML as a URL

I'm trying to send a response redirect at the end of a Java servlet post request:

session.setAttribute("token", token);
String redirectUrl = response.encodeRedirectURL(MYSITE_URL + "extras.html");
response.sendRedirect(redirectUrl)

      

The redirectUrl code execution matches "http://localhost:8080/mysite/extras.html"

. However, the browswer tries to request the following url, which to the observer is acutally the html of the document I am requesting.

http://localhost:8080/mysite/%3C!DOCTYPE%20html%3E%20%3Chtml%3E%20%20%20%20%20%3Chead%3E%20%20%20%20%20%20%20%20%20%3Ctitle%3EBet%20Ya%20Friends%3C/title%3E%20%20%20%20%20%20%20%20%20%3Cmeta%20name=%22viewport%22%20content=%22width=device-width,%20initial-scale=1%22%3E%20%20%20%20%20%20%20%20%20%3Clink%20rel=%22stylesheet%22%20href=%22http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css%22%20/%3E%20%20%20%20%20%20%20%20%3Cscript%20src=%22http://code.jquery.com/jquery-1.8.2.min.js%22%3E%3C/script%3E%20%20%20%20%20%20%20%20%3Cscript%20src=%22http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js%22%3E%3C/script%3E%20%20%20%20%3C/head%3E%20%20%20%20%20%3Cbody%3E%20%20%20%20%20%20%20%20%20%3Cdiv%20data-role=%22page%22%3E%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20data-role=%22header%22%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ch1%3EBet%20Ya%20Friends%3C/h1%3E%20%20%20%20%20%20%20%20%20%20%20%20%3C/div%3E%3C!--%20/header%20--%3E%20%20%20%20%20%20%20%20%20%20%20%20%3Cul%20data-role=%22listview%22%20data-inset=%22true%22%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Cdiv%3EView%20Friends%3C/div%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cspan%20class=%22ui-li-count%22%3E6%3C/span%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ECanary%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ECat%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EDog%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EGerbil%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EIguana%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EMouse%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/ul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Cdiv%3EMake%20A%20Bet%3C/div%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%20class=%22ui-li-count%22%3E6%3C/p%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EChicken%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ECow%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EDuck%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EHorse%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EPig%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ESheep%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/ul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Cdiv%3EBet%20History%3C/div%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%20class=%22ui-li-count%22%3E18%3C/p%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EAardvark%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EAlligator%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EAnt%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EBear%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EBeaver%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ECougar%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EDingo%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EEagle%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EElephant%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EFerret%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EFrog%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EGiraffe%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ELion%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EMonkey%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EPanda%20bear%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EPolar%20bear%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3ETiger%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cli%3E%3Ca%20href=%22index.html%22%3EZebra%3C/a%3E%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/ul%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/li%3E%20%20%20%20%20%20%20%20%20%20%20%20%3C/ul%3E%20%20%20%20%20%20%20%20%3C/div%3E%3C!--%20/page%20--%3E%3C!--%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ca%20href=%22#%22%20onclick=%22getUserFriends%28%29;%22%3EGet%20friends%3C/a%3E%3Cbr%3E%20%20%20%20%20%20%20%20%20%3Cdiv%20id=%22user-friends%22%3E%3C/div%3E%20%20%20%20%20%20%20%20%20%3Cscript%3E%20%20%20%20%20%20%20%20%20function%20getUserFriends%28%29%20{%20%20%20%20%20%20%20%20%20%20%20FB.api%28%27/me/friends&fields=name,picture%27,%20function%28response%29%20{%20%20%20%20%20%20%20%20%20%20%20%20%20console.log%28%27Got%20friends:%20%27,%20response%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20%28!response.error%29%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20markup%20=%20%27%27;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20friends%20=%20response.data;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20%28var%20i=0;%20i%20%3C%20friends.length%20&&%20i%20%3C%2025;%20i++%29%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20friend%20=%20friends[i];%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markup%20+=%20%27%3Cimg%20src=%22%27%20+%20friend.picture%20+%20%27%22%3E%20%27%20+%20friend.name%20+%20%27%3Cbr%3E%27;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20document.getElementById%28%27user-friends%27%29.innerHTML%20=%20markup;%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20}%29;%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%3C/script%3E--%3E%20%20%20%20%3C/body%3E%3C/html%3E

      

My question is why? Why is the actual html document requested and not the url? And why doesn't encodeURL encode the session into a URL?

+3


source to share


1 answer


You mentioned that MYSITE_URL

"localhost:8080/mysite/"

... This could be a problem. Its missing http at the beginning. Can you change MYSITE_URL to



"http://localhost:8080/mysite/"

and then try?

0


source







All Articles