JSP文件操作的问题,各位DFW帮帮我啊!!(75分)

  • 主题发起人 bukelong
  • 开始时间
用不用的上都说声,好吧。
import java.io.StringReader;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
public class TestParser2 extends HTMLEditorKit.ParserCallback{
String outerHTML = "<html ><head ><title >Hello World! </title></head><body><h1></h1><P><font color='red' size='9pt'>ABC</font><P>CDE<BR>EFT</P></body></html>";
StringReader in = null;
HTML.Tag m_CurTag = null;

public TestParser2() throws Exception{
init();
}

public void init() throws Exception{
in = new StringReader(outerHTML);
System.out.println(outerHTML);
new ParserDelegator().parse(in, this, true);
in.close();
in = null;
}

public void handleComment(char[] data, int pos) {
System.out.println("Comment: " + new String(data));
}
public void handleText(char[] data, int pos) {
if (m_CurTag != null)
System.out.println("Tag: " + m_CurTag + "'s innerText: " + new String(data));
}
public void handleError(String msg, int pos) {
System.out.println("Error: "+msg);
}

public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
System.out.println("Simple Tag: " + t);
}

public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
m_CurTag = t;
System.out.print("Tag Start: " + t);
java.util.Enumeration names = a.getAttributeNames();
while (names.hasMoreElements()){
// 如果强制转换为字符串出错!
Object attrName = names.nextElement();

System.out.print(" " + attrName + "=/"" + a.getAttribute(attrName) + "/"");
}
System.out.println();
}

public void handleEndTag(HTML.Tag t, int pos) {
m_CurTag = null;
System.out.println("Tag End: " + t);
}
public static void main(String[] args) throws Exception{
new TestParser2();
}
}
 
怎么没有反馈? :(
 
在 public void handleText(char[] data, int pos) 方法里面可以取得 Title:
if (m_CurTag == HTML.Tag.TITLE) System.out.println("God! Title is: " + data);
 
多人接受答案了。
 
解决了没有?怎么解决的?
 

Similar threads

回复
0
查看
860
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
932
SUNSTONE的Delphi笔记
S
顶部