Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating HTML tags (like CGI.pm does)

Status
Not open for further replies.

fishiface

IS-IT--Management
Feb 24, 2003
687
GB
I'm a novice java programmer writing scripts to generate HTML pages. All the examples I've found use code like
Code:
strHTML += "<a href=\"" + strURL + "\">";
strHTML += strLinkText + "</a>\n";

I've been writing in perl for many years and the standard module, CGI.pm, allows me to use syntax like
Code:
$HTML .= a( {-href=>$strURL}, $strLinkText );

This is much easier to read, much easier to code (you don't have to keep track of closing tags) and lets you virtually forget about encoding, escaping or quoting problems, to which the first example above would be particularly prone.

Is there a java class (I hope that's the correct terminology) that I can use to perform the same function - i.e. generate well-formed HTML tags with their attributes and arguments properly escaped and/or encoded? I've checked the FAQ and done several searches on this forum without success. Several search engines were similarly unforthcoming.

If there is no such standard class, would it be possible to abuse an XML generator class or can anyone point me towards a third-party solution?

I'm still struggling to find a java community equivalent to CPAN so please forgive me if I'm missing something obvious.

Yours,


fish

[&quot;]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.[&quot;]
--Maur
 
Sorry folks, I think this is the wrong forum. Although I'm using a j2ee environment I think that this is a plain java issue. I'll repost in the Java forum.

Yours,

fish

[&quot;]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.[&quot;]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top