Now, if I want to display an image in a jsp and then use some logic to redisplay a second image in the same location on the page, how do I do it? The above is hard coded. In a jsp I cannot build a string and then display it, i.e.
String h = "<img src=" + s + "width=/""70" ... etc; %>
the logic is on the server. the problem is not making the decision, it is the technical matter of displaying different images on a web page. Imagine the page shows some playing cards (jpeg files). Is it possible to keep the table static and use the servlet to write different images (cards) to the same location on the page? I can't see how to get round the fact that the HTML is not flexible.
I'm with Ulf in not understanding your issue. It's a pretty straight-forward type of operation that I've used many times; unless youve needlessly complicated your JSP page.
Why one earth are you building up markup in Java strings inside a JSP? The whole purpose of a JSP is to serve as a template for markup, not generate it in code. [ March 31, 2007: Message edited by: Bear Bibeault ]
which will display the image called image.jpg located at directory path. Now if I want to display a second image in the same position on the page, i.e. overlay a second image, how do I do it?
the code in my former posts simply showed how I had failed. If I define an image, then I either have to generate an entirely new page with the second image in the same place or I can overwrite the content of the file at path/image.jpg. Neither seem very good options if I am trying to play cards. I was inviting the experts to suggest a solution.
At what point do you want to replace the first image with the second?
Joined: Mar 22, 2005
Joined: Nov 30, 2003
Hi there Bear and Ulf,
Lets drop back a bit and review the concept of Model - View - Controller - a handy way of looking at the separation of function. In you case of representing a hand of cards on the user's browser and its interaction with a game, a breakdown could be:
Model: the identity of cards in the players hand - great for a server class
Controller: the logic that shows which cards interact with the game based on user input - once again the servlet side is the place for this.
Thanks for the advise about how do design the app, but i am still in the concept stage and my question is a very simple one! If I want to display a page with a selection of images that are not known in advance and therefore cannot be coded in html
i.e. <img src="path/file" etc
because the file name is not known, how is it done? do i specify a dummy file name and then create the file on the fly? or can I somehow dynamically create the html? I suppose I could use servlet println statements, but I feel sure the wickedly smart team would be very disappointed!
Come on, guys, I'm sure there is something simple that I am missing!
To be quite honest, I really haven't a clue as to what your issue really is.
Originally posted by Simon Ingram: because the file name is not known, ...
Why is it not know? When will it be known? How will it come to be known?
do i specify a dummy file name and then create the file on the fly?
can I somehow dynamically create the html?
Yeah, that's what JSPs do.
I'm sure there is something simple that I am missing!
I'm sure there is, because this should be butt-simple. But you're not communicating where your disconnect is very well.
For example, why are the image names not known at JSP execution time? I can't think of why and you haven't explained it in any way that enlightens me. [ April 03, 2007: Message edited by: Bear Bibeault ]
Joined: Nov 30, 2003
Sorry I am not making myself clear. At least we agree there is a butt simple solution to this, so let me try again:
If I have image files that contain playing cards Ac.jpg = ace clubs, 2c.jpg = two clubs etc
now I want to display a screen with some cards on it. My servelt can decide which cards to display and then forwards to a jsp. But when I write the jsp i don't know the cards, they are decided at run time and this is my problem. When I write the jsp the only way I know to display an image is to use the HTML <img> tag and for this I must specify an image file. But I don't know it!
Assuming that you are using JSP 2.0 and have JSTL 1.1 set up (and if not, you should), let's assume that the servlet provides the six card names as a string array and places it as a scoped variable named cards on the request.
Again this assumes a JSP 2.0 container such as Tomcat 5.x and the use of JSTL 1.1. If you are not set up as such, now is the time. Anything else is learning old crap that you're just going to have to unlearn.
Joined: Nov 30, 2003
don't want to appear ungrateful, but is there any way to do it just using java (scriptlets). I know you will tell me tags are great and intuitive and marvellous for web designers. But... can it be done without the tags?