我在linux上的resin配置中配置了一个web应用,其中在我的web应用中配置了一个自动的服务(就是每隔一分钟调用一个我的servlet,servlet再调用我的一个类中的方法),在我的这个方法中就是用
java.net.Url 来发送一个http请求然后取得一个流,将请求后生成的页面代码读取出来然后生成一个静态的html文件。代码如下:
public class MakeHtmlBOC
{
static InputStream in=null;
static FileOutputStream out_ex=null;
public static Stack stack;
public static void makeHtml()
{
String actionurl=null;
String filepath=null;
//读取地址
try
{
PropertiesFile oPF = new PropertiesFile("filepath.properties");
Properties oProperties = oPF.getFile();
actionurl = oProperties.getProperty("actionulr");
// System.out.println("actionulr:"+actionurl);
filepath = oProperties.getProperty("filepath");
// System.out.println("filepath"+filepath);
}catch(Exception ex)
{
ex.printStackTrace();
}
//取得一个栈
if(stack==null)
{
stack = new Stack();
}
//System.out.println("the size of stack:"+stack.size());
//取楼盘编号
if(stack.empty())
{
try
{
Session s = HibernateSessionFactory.currentSession();
String hql = "select t.houseId from THouse t";
Query qr = s.createQuery(hql);
Iterator it = qr.iterate();
while(it.hasNext())
{
stack.push((Integer)it.next());
}
// System.out.println("the stack size:"+stack.size());
}catch(Exception e)
{
e.printStackTrace();
}finally
{
try{
HibernateSessionFactory.closeSession();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
//写文件
try
{
String houseid = ((Integer)stack.pop()).toString();
actionurl+=houseid;
filepath+=houseid+".html";
// System.out.println("actionurl in write:"+actionurl);
// System.out.println("filepath in write:"+filepath);
// URL url=new URL("http://10.10.11.60:8080/fore/viewHouseDetailAction.do?houseId="+houseid);
URL url=new URL(actionurl);
in=url.openStream();
//out_ex=new FileOutputStream("F:\\myporject\\file\\aaa.html");
out_ex=new FileOutputStream(filepath);
byte[] arrIn=new byte[1024];
if(in!=null)
{
while(1>0)
{
int result=in.read(arrIn);
if(result==-1)
break;
out_ex.write(arrIn,0,result);
}
}
in.close();
out_ex.close();
}catch(Exception e)
{
e.printStackTrace();
}
// System.out.println("Read XML File Finish!");
//stack.pop();
}
}
现在问题是大概生成10来个静态页面后,程序再调用这个方法时,程序就停在这个方法中的http请求那里,(然后所有的每一分钟的调用都停在http请求那里)我的每一个http请求都通过struts到一个action中,我发现当停在这个方法的时候连action都没有进来。而且停了以后我访问一个jsp页面都不成功了,所有的一切都没有报异常,请教大侠。
java.net.Url 来发送一个http请求然后取得一个流,将请求后生成的页面代码读取出来然后生成一个静态的html文件。代码如下:
public class MakeHtmlBOC
{
static InputStream in=null;
static FileOutputStream out_ex=null;
public static Stack stack;
public static void makeHtml()
{
String actionurl=null;
String filepath=null;
//读取地址
try
{
PropertiesFile oPF = new PropertiesFile("filepath.properties");
Properties oProperties = oPF.getFile();
actionurl = oProperties.getProperty("actionulr");
// System.out.println("actionulr:"+actionurl);
filepath = oProperties.getProperty("filepath");
// System.out.println("filepath"+filepath);
}catch(Exception ex)
{
ex.printStackTrace();
}
//取得一个栈
if(stack==null)
{
stack = new Stack();
}
//System.out.println("the size of stack:"+stack.size());
//取楼盘编号
if(stack.empty())
{
try
{
Session s = HibernateSessionFactory.currentSession();
String hql = "select t.houseId from THouse t";
Query qr = s.createQuery(hql);
Iterator it = qr.iterate();
while(it.hasNext())
{
stack.push((Integer)it.next());
}
// System.out.println("the stack size:"+stack.size());
}catch(Exception e)
{
e.printStackTrace();
}finally
{
try{
HibernateSessionFactory.closeSession();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
//写文件
try
{
String houseid = ((Integer)stack.pop()).toString();
actionurl+=houseid;
filepath+=houseid+".html";
// System.out.println("actionurl in write:"+actionurl);
// System.out.println("filepath in write:"+filepath);
// URL url=new URL("http://10.10.11.60:8080/fore/viewHouseDetailAction.do?houseId="+houseid);
URL url=new URL(actionurl);
in=url.openStream();
//out_ex=new FileOutputStream("F:\\myporject\\file\\aaa.html");
out_ex=new FileOutputStream(filepath);
byte[] arrIn=new byte[1024];
if(in!=null)
{
while(1>0)
{
int result=in.read(arrIn);
if(result==-1)
break;
out_ex.write(arrIn,0,result);
}
}
in.close();
out_ex.close();
}catch(Exception e)
{
e.printStackTrace();
}
// System.out.println("Read XML File Finish!");
//stack.pop();
}
}
现在问题是大概生成10来个静态页面后,程序再调用这个方法时,程序就停在这个方法中的http请求那里,(然后所有的每一分钟的调用都停在http请求那里)我的每一个http请求都通过struts到一个action中,我发现当停在这个方法的时候连action都没有进来。而且停了以后我访问一个jsp页面都不成功了,所有的一切都没有报异常,请教大侠。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货