Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make URL connection to servlet in j_security_check form based authentication

elay Raja
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make connection to servlet which is residing in tomcat under form based authentication using j_security_check.
The code which i used to read the content from the given URL is shown below.
Actually the servlet is in server1.I am accessing from server2.
URL urlServlet = new URL("https://server1/TestServlet");
HttpsURLConnection con = (HttpsURLConnection) urlServlet.openConnection();
con.setRequestProperty("Date", new Date().toString());
con.setRequestProperty("Content-Length", "0");

BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println("XML is:"+line);
When i connect to this URL it will be redirected to login page,since it is in form based authentication using j_security_check.when i print the streams from the URL,the html content of the login page of my application is displayed.I had configured the SSL also.I want to read the content of the URL.Please help me to resolve this issue.
[ August 21, 2008: Message edited by: elay Raja ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic