retrieve info from jsp file with session
843836Apr 27 2004 — edited Apr 28 2004Hello! I have a login page "index.jsp" with login name and password, Once the user successfully logs in, the second page "home.jsp" is opened. In this page I have the following code
<% String id = session.getAttribute("user").toString(); %>
whereas in "index.jsp" I define the session as follows:
<% session.setAttribute("user", request.getParameter("userName")); %>.
I use the following code "TestUrl.java" to retrieve the content of both pages:
try
{
URL url = new URL("http://path/index.jsp?passWord=1&userName=yy");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection. getInputStream()));
String line = in.readLine();
while(line != null){
System.out.println(" " +line);
line = in.readLine();
}
in.close();
url = new URL("http://path/home.jsp");
connection = (HttpURLConnection)url.openConnection();
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
line = in.readLine();
while(line != null){
System.out.println(" " +line);
line = in.readLine();
}
in.close();
}
catch (MalformedURLException me)
{
System.out.println("Error: Initialize URL Failed");
}
catch (UnknownHostException host)
{
System.err.println("Host Unknown:" + host.getMessage());
}
catch (IOException host)
{
System.err.println("IO exception:" + host.getMessage());
}
After I run TestUrl, it gives me the error:
IO exception:Server returned HTTP response code: 500 for URL: http://path/home.jsp
I suspect the reason is when the second connection is made, a new session is created. For example if I add session.setAttribute("user", "yy"), then the page home.jsp can be retrieved. My question is :
Is there a way to send multiple HTTP requests while staying in one connection?
sincerely,