Simple HTML-Building Utilities

By: aathishankaran Emailed: 1700 times Printed: 2205 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

 

An HTML document is structured as follows:

 

<!DOCTYPE ...>

<HTML>

<HEAD><TITLE>...</TITLE>...</HEAD>

<BODY ...>

...

</BODY>

</HTML>

 

You might be tempted to omit part of this structure, especially the DOCTYPE line, noting that virtually major browsers ignore it, even though the HTML 3.2 and 4.0 specifications require it.

 

servletc.bat

 

@echo off

rem This is the version for the Java Web Server.

rem See http://www.coreservlets.com/ for other versions.

set CLASSPATH=C:\JavaWebServer2.0\lib\servlet.jar;

C:\JavaWebServer2.0\lib\jsp.jar;

C:\MyServlets

C:\JDK1.1.8\bin\javac -d C:\JavaWebServer2.0\servlets %1%

 

http://hostname/servlet/packagename.servletName.

 

I strongly discourage this practice. The advantage of the DOCTYPE line is that it tells HTML valuators which version of HTML you are using, so they know which specification to check your document against. These valuators are very valuable debugging services, helping you catch HTML syntax errors that your browser guesses well on, but that other browsers will have trouble displaying. The two most popular on-line valuators are the ones from the World Wide Web Consortium (http://validator.w3.org/) and from the Web Design Group (http://www.htmlhelp.com/tools/validator/). They let you submit a URL, and then they retrieve the page, check the syntax against the formal HTML specification, and report any errors to you. Since a servlet that generates HTML looks like a regular Web page to visitors, it can be validated in the normal manner unless it requires POST data to return its result. Remember that GET data is attached to the URL, so you can submit a URL that includes GET data to the valuators.

 

Admittedly it is a bit cumbersome to generate HTML with println statements, especially long tedious lines like the DOCTYPE declaration. Some people address this problem by writing detailed HTML generation utilities in Java, and then use them throughout their servlets. I’m skeptical of the utility of an extensive library for this. First and foremost, the inconvenience of generating HTML programmatically is one of the main problems addressed by Java Server Pages (discussed in the second part of this book). JSP is a better solution, so don’t waste effort building a complex HTML generation package.

Second, HTML generation routines can be cumbersome and tend not to support the full range of HTML attributes (CLASS and ID for style sheets, JavaScript event handlers, table cell background colors, and so forth). Despite the questionable value of a full-blown HTML generation library, if you find you’re repeating the same constructs many times, you might as well create a simple utility file that simplifies those constructs. For standard servlets, there are two parts of the Web page (DOCTYPE and HEAD) that are unlikely to change and thus could benefit from being incorporated into a simple utility file.

 


JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
JSP CheckBox Example
The JSP Program running first Time.
Tags using in jsp
Simple HTML-Building Utilities
Retrieving a Portion of a String
Comparison operators in JSP
Automatically Including Preludes and Codas in JSP
The BodyTag Interface in JSP
Encrypting Passwords in Tomcat using Servlets
JSP Example to connect to MS SQL database and retrieve records
Using UTF-8 in JSP / ASP / HTML pages.
Writing your first JSP page
Getting Started with JSP
The Exception Object in JSP
Most Emailed Articles (in JSP)
What is JSP?
Declaring variable in JSP
A Servlet That Generates HTML
Retrieving a Portion of a String
JSP Example to connect to MS SQL database using Tomcat Connection Pool
The Application Object in JSP
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Scriptlets
Server Side Programming
Syntax For JSP Declaratives
Embedding java codes in jsp sciptlets
Tags using in jsp
JSP pages in servlet