This discussion is archived
6 Replies Latest reply: Feb 14, 2012 8:22 AM by gimbal2 RSS

Login and redirect only with Java

861266 Newbie
Currently Being Moderated
Hello.
I have an application and i saw that by url i can get logged and redirect. First i do http://test/servlet?user=xxx?password=xxx, then i can write every page i want into that application like http://test/grapgycs, where i needed to be loged in. (logging uses POST)

I need do that from Java (a servlet which shoul log me in and redirect). I'm trying something like

URL urlRequestDetail = new URL(url);
HttpURLConnection urlConnectionRequestDetail = (HttpURLConnection)urlRequestDetail.openConnection();
urlConnectionRequestDetail.setRequestMethod("POST");
urlConnectionRequestDetail.setDoOutput(true);
urlConnectionRequestDetail.setDoInput(true);     
OutputStreamWriter outRequestDetail = new OutputStreamWriter(urlConnectionRequestDetail.getOutputStream());
outRequestDetail.write("user=xxx");
outRequestDetail.write("password=xxx");

After that i'm trying this but servlet dont redirect.
String site = http://test/grapgycs
res.setStatus(res.SC_SEE_OTHER);
res.setHeader("Location", site);

This doesnt work.
Whats wrong ????

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points