用户提交带格式的一段html代码,一方面需要将html代码存储;另外,在输出内容简介时希望将除控制文本格式的标签外的内容提取出来。如何去做?在java中实现,请问有相关API吗?谢谢。
解决方案 »
- 一个登陆的问题,session可以跨浏览器这是为什么啊
- 为什么session.getAttribute得到的是空值
- 一个高难度的socket编程有谁帮我解决
- 如何实现URL重写?
- 我不会java,哪位大哥帮我把MSSQL数据库中的图片路径调出来~~100分谢谢~~
- 请教一个问题!如何分页显示!
- 使用jdbc连接服务器上的mysql出错,但是本地正常
- 用摄像头可以在NetMeeting中进行图像的网络传输吗?
- Jsp里有没有类似Asp的Session_OnStart,Session_OnEnd
- 关于用AOP统计service运行时间的问题,在线等
- 这段asp代码怎样使它在JSP有用
- jbuilder2007中数据库的连接问题 急急急急急急
from: http://forum.java.sun.com/thread.jspa?threadID=778434&messageID=4429791org.htmlparser.parserapplications.StringExtractor或者
Or, using classes from the JDK:import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
class GetHTMLText
{
public static void main(String[] args)
throws Exception
{
EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
// The Document class does not yet handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
// Create a reader on the HTML content.
Reader rd = getReader(args[0]);
// Parse the HTML.
kit.read(rd, doc, 0);
// The HTML text is now stored in the document
System.out.println( doc.getText(0, doc.getLength()) );
}
// Returns a reader on the HTML data. If 'uri' begins
// with "http:", it's treated as a URL; otherwise,
// it's assumed to be a local filename.
static Reader getReader(String uri)
throws IOException
{
// Retrieve from Internet.
if (uri.startsWith("http:"))
{
URLConnection conn = new URL(uri).openConnection();
return new InputStreamReader(conn.getInputStream());
}
// Retrieve from file.
else
{
return new FileReader(uri);
}
}
}