aspose file tools*
The moose likes Java in General and the fly likes Java HTML URL construction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java HTML URL construction" Watch "Java HTML URL construction" New topic
Author

Java HTML URL construction

peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 35
Hi every body I am generating HTML via java having just a bit of trouble with url construction so i am typically using

data.writeTofile("<h2><font color = blue>is a stock picture</font></h2>"); which works just fine together with the rest of the code to make the webpage

now i have a working url which pulls in a picture of a book, to be accurate its a picture of a blank to indicate that a picture is not available you can view this by pasting this http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif in to the address bar or this code in an html document


data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif' width='167' height='280'/>");

now what i am trying to do is replace the last part with a variable so that i can select different books to display at the moment the are a few books on this webspace an example of which is The Arabian Nights) Childrens Classics so changing no-image.gif for 9781858137162.jpg works fine

If however i substitute no-image.gif for a variable lets call it the lastbit and try to construct the url then it does not work can anyone tell me why or tell me how to solve the problem

so just to be clear


data.writeTofile("<h2><font color = blue>is a stock picture</font></h2>"); i use this type of arrangement to generate the html


data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif' width='167' height='280'/>");

works fine

String lastbit ="no-image.gif"; this is so i can change to say lastbit ="9781858137162.jpg";

does not work why?

data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/lastbit' width='167' height='280'/>");

if i change no-image.gif to 9781858137162.jpg manually it does work




Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

peter m hayward wrote:does not work why?

data.writeTofile("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/lastbit' width='167' height='280'/>");


That is a string literal. It does not use or attempt to use any variable. Just because you have a string with the same couple of characters as the variable name does not mean that those characters will be replaced by the variable. You have to actually use the variable. Maybe something like this will work:


I am sure there are better libraries for writing HTML in Java than you writing your own. This all looks very fragile to me. I think you should investigate some tool to use to handle the HTML writing for you.


Steve
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java HTML URL construction