tt.jsp页面
http://www.blogjava.net/pengo/archive/2011/03/14/346176.html
[HTML]代码
01
<%@ page language="java" contentType="text/html; charset=UTF-8"
02
pageEncoding="UTF-8"%>
03
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
04
<html>
05
<head>
06
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
07
<title>Insert title here</title>
08
</head>
09
<body>
10
测试连接
11
<a href="http://www.blogjava.net/pengo/">penngo的博客</a>
12
<a href="http://www.blogjava.net/">blogjava博客</a>
13
</body>
14
</html>
Activity01.java
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Activity01 extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
String myString = null;
StringBuffer sff = new StringBuffer();
try
{
Document doc = Jsoup.connect("http://192.168.64.9:8099/AgentJava/tt.jsp").get();
Elements links = doc.select("a[href]");
for(Element link : links){
sff.append(link.attr("abs:href")).append(" ").append(link.text()).append("\n");
}
myString = sff.toString();
}
catch (Exception e)
{
myString = e.getMessage();
e.printStackTrace();
}
/* 将信息设置到TextView */
tv.setText(myString);
/* 将TextView显示到屏幕上 */
this.setContentView(tv);
}
}