<%@ page language="java" import="java.util.*,java.io.*,java.net.*,java.util.regex.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'href.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
Pattern p = null; //正则表达式
Matcher m = null; //操作的字符串
boolean b = false;
String sCurrentLine = "";
String sTotalString = "";
InputStream l_urlStream;
java.net.URL l_url = new java.net.URL("http://www.chinaventure.com.cn/");
HttpURLConnection l_connection =(HttpURLConnection)l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
if(l_reader.readLine()== null){
System.out.println(l_reader.ready());
}
System.out.println(l_reader.readLine());
System.out.println(sCurrentLine);
while ((sCurrentLine = l_reader.readLine()) != null){
//sCurrentLine="65465.56";
p = Pattern.compile("[0-9]+.[0-9]+");
//sCurrentLine="<a face='Arial' size='+2' color='red'>";
//p = Pattern.compile("");
m = p.matcher(sCurrentLine);
b = m.matches();
System.out.println(sCurrentLine);
System.out.println(b);
if(b){
//String url = sCurrentLine.substring(sCurrentLine.indexOf("<a href"),sCurrentLine.indexOf(">"));
sTotalString += sCurrentLine;
//System.out.println(url);
}
}
System.out.println(sTotalString);
%>
</body>
</html>------------------------------------------------------------------------------------------------
就一个jsp页面
while条件里判断的是当前读取的行
可是遇到null值就不读取下一行了
java.net.URL l_url = new java.net.URL("http://www.chinaventure.com.cn/");
把这里面的网址换一个就基本没有问题了
可是又必须要这个页面才可以 而且这个页面的html代码的第一行没东西
怎么办啊,
我可不可以在readline()为空值的时候让readline()为""字符串啊,或者是给当前行重新赋值...
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'href.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
Pattern p = null; //正则表达式
Matcher m = null; //操作的字符串
boolean b = false;
String sCurrentLine = "";
String sTotalString = "";
InputStream l_urlStream;
java.net.URL l_url = new java.net.URL("http://www.chinaventure.com.cn/");
HttpURLConnection l_connection =(HttpURLConnection)l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
if(l_reader.readLine()== null){
System.out.println(l_reader.ready());
}
System.out.println(l_reader.readLine());
System.out.println(sCurrentLine);
while ((sCurrentLine = l_reader.readLine()) != null){
//sCurrentLine="65465.56";
p = Pattern.compile("[0-9]+.[0-9]+");
//sCurrentLine="<a face='Arial' size='+2' color='red'>";
//p = Pattern.compile("");
m = p.matcher(sCurrentLine);
b = m.matches();
System.out.println(sCurrentLine);
System.out.println(b);
if(b){
//String url = sCurrentLine.substring(sCurrentLine.indexOf("<a href"),sCurrentLine.indexOf(">"));
sTotalString += sCurrentLine;
//System.out.println(url);
}
}
System.out.println(sTotalString);
%>
</body>
</html>------------------------------------------------------------------------------------------------
就一个jsp页面
while条件里判断的是当前读取的行
可是遇到null值就不读取下一行了
java.net.URL l_url = new java.net.URL("http://www.chinaventure.com.cn/");
把这里面的网址换一个就基本没有问题了
可是又必须要这个页面才可以 而且这个页面的html代码的第一行没东西
怎么办啊,
我可不可以在readline()为空值的时候让readline()为""字符串啊,或者是给当前行重新赋值...
解决方案 »
- JDOM ,windows7 ,tomcat 谁的bug?
- webService抛出 org.apache.axis2.AxisFault异常
- 跪求:Myeclipse+tomcat5+MySQL数据源配置问题
- extjs和struts2的参数传递问题
- hibernate如何操作clob
- 一个关于switch的问题
- 注解在什么情况才可以使用啊?
- 菜鸟在线请教JSP运行问题
- jquery xml对象 转字符串
- 为什么不能更新呢
- 请问:Cannot create iterator for this collection 这个错误是怎么引起的?
- 百度以及google提交搜索的 /s 链接是如何实现的?
===============================================
那你怎么退出循环?