Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - html web
Search - html web - List

Java编写HTML文件分析程序

 一、概述

    

    Web服务器的核心是对Html文件中的各标记(Tag)作出正确的分析,一种编程语言的解释程序也是对源文件中的保留字进行分析再做解释的。实际应用中,我们也经常会碰到需要对某一特定类型文件进行要害字分析的情况,比如,需要将某个HTML文件下载并同时下载与之相关的.gif.class等文件,此时就要求对HTML文件中的标记进行分离,找出所需的文件名及目录。在Java出现以前,类似工作需要对文件中的每个字符进行分析,从中找出所需部分,不仅编程量大,且易出错。笔者在近期的项目中利用Java的输入流类StreamTokenizer进行HTML文件的分析,效果较好。在此,我们要实现从已知的Web页面下载HTML文件,对其进行分析后,下载该页面中包含的HTML文件(假如在Frame中)、图像文件和ClassJava Applet)文件。

    

    二、StreamTokenizer

    

    StreamTokenizer即令牌化输入流的作用是将一个输入流中变成令牌流。令牌流中的令牌实体有三类:单词(即多字符令牌)、单字符令牌和空白(包括JavaC/C++中的说明语句)。

    

    StreamTokenizer类的构造器为: StreamTokenizer(InputStream in)

    

    该类有一些公有实例变量:ttypesvalnval ,分别表示令牌类型、当前字符串值和当前数字值。当我们需要取得令牌(即HTML中的标记)之间的字符时,应访问变量sval。而读向下一个令牌的方法是调用nextToken()。方法nextToken()的返回值是int型,共有四种可能的返回:

    

    StreamTokenizer.TT_NUMBER: 表示读到的令牌是数字,数字的值是double型,可以从实例变量nval中读取。

    

    StreamTokenizer.TT_Word: 表示读到的令牌是非数字的单词(其他字符也在其中),单词可以从实例变量sval中读取。

    

    StreamTokenizer.TT_EOL: 表示读到的令牌是行结束符。

    

    假如已读到流的尽头,则nextToken()返回TT_EOF

    

    开始调用nextToken()之前,要设置输入流的语法表,以便使分析器辨识不同的字符。WhitespaceChars(int low, int hi)方法定义没有意义的字符的范围。WordChars(int low, int hi)方法定义构造单词的字符范围。

    

    三、程序实现

    

    1HtmlTokenizer类的实现

    

    对某个令牌流进行分析之前,首先应对该令牌流的语法表进行设置,在本例中,即是让程序分出哪个单词是HTML的标记。下面给出针对我们需要的HTML标记的令牌流类定义,它是StreamTokenizer的子类:

    

    

    import java.io.*;

    import java.lang.String;

    class HtmlTokenizer extends

    StreamTokenizer {

    //定义各标记,这里的标记仅是本例中必须的,

    可根据需要自行扩充

     static int HTML_TEXT=-1;

     static int HTML_UNKNOWN=-2;

     static int HTML_EOF=-3;

     static int HTML_IMAGE=-4;

     static int HTML_FRAME=-5;

     static int HTML_BACKGROUND=-6;

     static int HTML_APPLET=-7;

    

    boolean outsideTag=true; //判定是否在标记之中

    

     //构造器,定义该令牌流的语法表。

     public HtmlTokenizer(BufferedReader r) {

    super(r);

    this.resetSyntax(); //重置语法表

    this.wordChars(0,255); //令牌范围为全部字符

    this.ordinaryChar('< '); //HTML标记两边的分割符

    this.ordinaryChar('>');

     } //end of constrUCtor

    

     public int nextHtml(){

    int token; //令牌

    try{

    switch(token=this.nextToken()){

    case StreamTokenizer.TT_EOF:

    //假如已读到流的尽头,则返回TT_EOF

    return HTML_EOF;

    case '< ': //进入标记字段

    outsideTag=false;

    return nextHtml();

    case '>': //出标记字段

    outsideTag=true;

    return nextHtml();

    case StreamTokenizer.TT_WORD:

    //若当前令牌为单词,判定是哪个标记

    if (allWhite(sval))

     return nextHtml(); //过滤其中空格

    else if(sval.toUpperCase().indexOf("FRAME")

    !=-1 && !outsideTag) //标记FRAME

     return HTML_FRAME;

    else if(sval.toUpperCase().indexOf("IMG")

    !=-1 && !outsideTag) //标记IMG

     return HTML_IMAGE;

    else if(sval.toUpperCase().indexOf("BACKGROUND")

    !=-1 && !outsideTag) //标记BACKGROUND

     return HTML_BACKGROUND;

    else if(sval.toUpperCase().indexOf("APPLET")

    !=-1 && !outsideTag) //标记APPLET

     return HTML_APPLET;

    default:

    System.out.println ("Unknown tag: "+token);

    return HTML_UNKNOWN;

     } //end of case

    }catch(IOException e){

    System.out.println("Error:"+e.getMessage());}

    return HTML_UNKNOWN;

     } //end of nextHtml

    

    protected boolean allWhite(String s){//过滤所有空格

    //实现略

     }// end of allWhite

    

    } //end of class

    

    以上方法在近期项目中测试通过,操作系统为Windows NT4,编程工具使用Inprise Jbuilder3


Date : 2008-07-07 Size : 1.04kb User : tiberxu

该程序使用HTML视图添加web brwser控件功能。
Date : 2008-10-13 Size : 33.91kb User : mxq

这是我写的一个功能齐全的嵌入式web服务器,在友善之臂S3C2440板子上调试通过并验收。嵌入式设备具有有限的内存资源,所以在设计上要求嵌入式web服务器代码不仅要完成需求的所有功能,还要求代码尽可能的优化和精简。基于以上需求,完成了嵌入式web服务器所要求的基本功能: 1. 实现对静态网页请求的应答。 2. 实现对动态网页请求的应答,web服务器有执行外部程序的能力。 3. 可以同时接受和处理多个客户端的请求应答。 4. 有效防止僵尸进程的产生。 5. 错误处理。 -------------------------------- 因为嵌入式资源的限制,动态网页使用了cgi来处理,cgi程序可以用C语言或是脚本来编写,所有的cgi程序和外部执行程序要发布在cgi-bin文件夹中。代码中附带的home.html和add.html是为了测试代码所附加的两个简单的网页。home.html用于对请求静态网页的测试。add.html用于测试动态请求。如果你要测试web服务器执行外部程序可以把外部程序一起发布在cgi-bin中。我在自己的板子上测试,成功控制了板子的led灯。 ============== 这个嵌入式web服务器经过多次优化,代码精简高效。因为是急着要下个东西需要积分,把好东西拿处理分享了。
Date : 2011-03-30 Size : 128.13kb User : weareallhappy@vip.qq.com

JAVA 网页控件 v-create-JAVA web controls v-create
Date : 2025-12-18 Size : 24kb User : 于杰

代码名称: DBMEdit 1.0 添加日期: 2000-8-22 所属分类: CGI代码>数据库管理 总下载次数: 984 文件大小: 12KB 适用环境: UNIX 评定级别: 上传者: roland 下载地址: 按此下载 代码效果演示: 暂无 详细介绍: 以WEB方式添加、编辑、删除DBM数据库里面资料。-code name : DBMEdit 1.0 Add : 2000-8-22 respective classifications : CGI code gt; Database management total number of downloads : 984 Size : KB application environment : UNIX classification : upload : download roland address : Click here to download generation results demonstrated code : no details : WEB add, edit, delete DBM database inside information.
Date : 2025-12-18 Size : 11kb User : 王旭

1.支持中文验证码,让网站更加安全 2.采用ASP.NET 2.0技术制作 3.三层架构设计,层次分明,功能可拓展性强。 4.优化的缓存设计,执行速度是ASP类网站的3~4倍。 5.安全性更高,能够有效防范WEB攻击。 6.面向搜索引擎设计——采用URL重写技术,增加搜索引擎收录机会。 7.前后台代码分离,使前台界面修改更加容易。 8.可选风格及模板,可对不同分类和专题使用不同模板和风格显示充分满足客户要求。 9.功能强大的网页编辑器,方便进行图文混排。 0.新闻无限分类,并可添加专题,可对不同分类和专题用不同风格显示 11.动态生成HTML页面,减少服务器资源耗费。 12.增强的文件管理功能。 更新 1.最新添加动态模板加载功能,用户可以自己定义模板。 2.增加Url重写页面扩展名选择功能。 3.增强文章专题功能。 4.增加文件编辑功能。 修正: 1.修正无法删除上传文件的错误 2.修正了数据库的一处错误-1. Chinese support certification yards, two sites more secure. ASP.NET 2.0 technology used to produce 3. The three-tier design, structured, functions will be able to develop strong. 4. Optimization of cache design, implementation speed ASP website of 3 to 4 times. 5. Higher security to effectively guard against Web attacks. 6. Design-oriented search engines-- using URL rewriting technology, increase search engine included opportunities. 7. Taiwan code before and after separation, so that future changes easier interface. 8. Optional styles and templates, can be of different classification and the use of different thematic templates and style show fully meet customer requirements. 9. The powerful web editor, facilitate photo-text. 0. News unlimited, which could add topics to be different cl
Date : 2025-12-18 Size : 754kb User :

CSS就是Cascading Style Sheets,中文翻译为“层叠样式表”,简称样式表,它是一种制作网页的新技术。 网页设计最初是用HTML标记来定义页面文档及格式,例如标题<h1>、段落<p>、表格<table>、链接<a>等,但这些标记不能满足更多的文档样式需求,为了解决这个问题,在1997年W3C(The World Wide Web Consortium)颁布HTML4标准的同时也公布了有关样式表的第一个标准CSS1, 自CSS1的版本之后,又在1998年5月发布了CSS2版本,样式表得到了更多的充实。W3C把DHTML(Dynamic HTML)分为三个部分来实现:脚本语言(包括JavaScript、Vbscript等)、支持动态效果的浏览器(包括Internet Explorer、Netscape Navigator等)和CSS样式表。 -CSS is Cascading Style Sheets. the Chinese translation for "cascading style sheet," which is abbreviated style sheet, it is a website production of new technologies. Web page design was first used to define HTML tags and page document formats, such as title
Date : 2025-12-18 Size : 319kb User : 李强

这是一个静态网页编程的实例,主题是一个奥运会的排行榜其中必要的多有,无解压密码.-This is a static web programming examples, the theme is a list of the Olympic Games which are more necessary. without extracting passwords.
Date : 2025-12-18 Size : 3.97mb User : dzt

这是一个静态网页编程的实例,主题是一个个人情况表其中必要的多有,无解压密码.-This is a static web programming examples, the theme is a personal table which is more necessary, without extracting passwords.
Date : 2025-12-18 Size : 985kb User : dzt

一个开源heml语意分析器 ekhtml: The El-Kabong HTML parser SUMMARY: El-Kabong: A speedy, yet forgiving, SAX-stylee HTML parser. PROJECT INFORMATION: Web Site: ekhtml.sourceforge.net The web site contains links to locations where one can: - file bugs - join mailing lists - download the latest release - browse documentation - get CVS information BUILDING: See the file INSTALL for information、目标代码生成、符号表的构造和运行时存储空间的组织等8部分组成。-revenue heml a semantic analyzer ekhtml : The El-Kabong HTML parser SUMMARY : El-Kabong : A speedy, yet forgiving. SAX- stylee HTML parser. PROJECT INFORMATION : Web Site : ekhtml.sourceforge.net The web site contains links to locations where one can :- file bugs- join mailing lists-download the la test release-browse documentation- get in CVS formation BUILDING : See the file INSTALL for information, object code generation, symbol table structure and operation of storage space at the organization of eight components.
Date : 2025-12-18 Size : 265kb User :

用vc编写的一个在程序中嵌入HTML网页的实例,相当于是一个浏览器,能够通过输入网址而打开网页,是学习的好例子。-vc used in the preparation of a process embedded in HTML pages example, is equivalent to a browser, through the Web address and open the site, and is a good example to study.
Date : 2025-12-18 Size : 36kb User : 陈芳

包括web开发的各种特效,菜单,树形结构,列表,对话框等,使用方便,稳定。-include web development of various effects, menu, tree structure, list box, easy to use and stable.
Date : 2025-12-18 Size : 387kb User : luoqt

在对话框上能显示网页,COOL吧,以前这么想的-In the dialog box that can display web pages, COOL it previously thought
Date : 2025-12-18 Size : 168kb User : li

创易企业网站管理系统v2008后台地址/admin,后台帐号admin密码为admin. 基于asp+access开发, 快速稳定,功能更强大,全站生成html。 本文来源于虾客源码 http://www.xkxz.com-Chong Yi Enterprise Management System Web site address v2008 background/admin, background account for the admin password admin. Based on asp+ Access development, rapid stable, more powerful, full-stop to generate html. This article comes from shrimp-off source http://www.xkxz.com
Date : 2025-12-18 Size : 471kb User : gc

Web课程设计 一个简单的选课系统,可以实现教师、学生和管理员的三级管理-Web course design a simple selection system can be achieved by teachers, students and administrators at the three levels of management
Date : 2025-12-18 Size : 4.59mb User : 于富强

网址导航,2008最新,收录点击排行,20点生成给色,全站html-Web site navigation, 2008, the latest collection click on Top, 20-point generating the color, the whole station html
Date : 2025-12-18 Size : 1.6mb User : 000000000000

新生注册系统,用JSP和WEB数据库表写的系统,可以进行删除,添加,管理等操作.-Student registration system, and WEB use JSP to write the system database tables, you can delete, add, and management operations.
Date : 2025-12-18 Size : 1.45mb User : liberty

HTML语言剖析,对HTML语言进行了详细的介绍,并教了如何用源码制作网页,是HTML学习的初学者很好的资料。-HTML language analysis, on the HTML language introduced in detail, and teach how to use web pages source code is good for beginners to learn HTML data.
Date : 2025-12-18 Size : 436kb User :

深入浅出HTML mooc网网站学习搭建源码实例教程-html web program
Date : 2025-12-18 Size : 5.79mb User : 吴浩然

本任务利用正则表达式解析给定的《The Merchant of Venice》 HTML网页文件,并将文件内容按Markdown格式 存储至文件中(This task uses regular expressions to analyze the given "the merchant of Venice" HTML web page file and store the contents of the file in markdown format)
Date : 2025-12-18 Size : 46kb User : 哈哈飞
« 12 3 4 5 6 7 8 »
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.