File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Alternative banners displaying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Alternative banners displaying" Watch "Alternative banners displaying" New topic

Alternative banners displaying

Gadi Reddy

Joined: Jan 10, 2006
Posts: 21
Hello All,
How are you?
i need to display the Alternative flash banners in the website.
first time it opens one flash banner, when i refresh it will show another banner.Please help me java code/javascript.

Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
This could be possible using a session attribute.
so that the first time the page is loaded, and the HTTP session that gets created would not contain any custom attributes your app would stuff on it.
So you can look for / set a session attribute that can be used to render the output for the first page load, or different content there after

in the JSP:

Note that by using a date as the object for the first visit within this session, it could be used by something else in your app, like to show different content as the user continues to reload the page over time , during the span of their session.

Error: Keyboard not attached. Press F1 to continue.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 812
I have one more idea !
you can use Jsp init parameter in web.xml like

suppose there are five different images, and we can choose randomly 5 images on each request
<!-- Init parameters for the JSP readInitParamJSP -->
<servlet-name>readInitParamJSP</servlet-name> <jsp-file>/web/readInitParamJSP.jsp</jsp-file>
<param-value>path to image 1</param-value>
<param-value>path to image 2</param-value>
and other 3 init parameter for ohter 3 images
<servlet-name>readInitParamJSP</servlet-name> <url-pattern>/web/readInitParamJSP.jsp</url-pattern>


in jsp you can use following code

int a = (int)(Math.random()*100)/20;
Stirng str= Integer.toString(a);
String parameter =config.getInitParameter(str);

<img src=<%=parameter%> />

i think it should work !!!

Thanks and Regards, Amit Taneja
I agree. Here's the link:
subject: Alternative banners displaying
It's not a secret anymore!