Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't connect on first attempt

Status
Not open for further replies.

TheObserver

Programmer
Mar 26, 2002
91
US
Hello. I’ve got a struts action class that connects to a webservice to pull over some data. I’m accessing the service with the following code in my java class:

[tt]
StringBuffer mySB = new StringBuffer();
String serviceAddress = "URL myURL = new URL(serviceAddress);
URLConnection conn = myURL.openConnection();

DataInputStream in = new DataInputStream (conn.getInputStream ());
BufferedReader d = new BufferedReader(new InputStreamReader(in));

while(d.ready())
{
mySB.append(d.readLine());
}

String ret = mySB.toString();
[/tt]

When I initially load up the JSP that uses this action class, the data doesn’t show up, and the server logs don’t show any errors. If I refresh the JSP, the data shows up.

Has anyone seen anything like this? I've been unable to find any information to help out. Thanks for your time.
 
Are you sure the JSP is being loaded the first time, ie, is the class actually being called?

Cheers,
Dian
 
Try to add the following lines into your jsp.
Code:
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

// Is there any proxy server prevent your program?
Your program run fine in reading the web page on Tomcat server on localhost.

String serviceAddress = "
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top