Skip to content
Advertisement

How to add image along with title name for all pages in that project in one code in Struts 2

I wrote the mentioned code

<link rel="Shortcut icon" href="img/favicon.ico"/>

in head section of JSP page and it is able to display the image along with the title name of the page but what I want is it should be reflected on all my pages of project. So what should be done ?

Note: Made a favicn.ico and environment is Java Struts 2

Advertisement

Answer

Create a main page called for example baseLayout.jsp, which has a section for header, body, footer, toolbar, etc.

Each section you should include using Struts include tag or similar. In this page you have a head where you can put your link tag. As well as this page will be returned by every action, with exception to those actions that return redirect like results, you will have a link on every page.

This is the same concept that used in Tiles framework, where you can define a layout in the tiles config file and use tiles result type to return by the actions.

Another approach is to create a JSP file with only the link and include it on every page, but it’s less productive as above solution.

If you are not familiar with Tiles framework you can read this answer to get started.

I’m thinking of using simple features such as a side bar for navigation and banner across the top with the website name etc, and would like this to be carries across every page.

you are definitely needed tiles and tiles integration with Struts 2 via the tiles-2 plugin or tiles-3 plugin

there’s plenty tutorials with examples on the web on these theme, for example

I have read that to do this in JSP I have to use tag files (stored in the WEB-INF folder) then link to these on each JSP page?

Tags is a bit outdated, however in the JSP you should use struts tags

Also I have seen people creating these banners and sidebars etc in Photoshop, is this what normally goes on in web site development?

Yes, that banners, images, designed with it.

To sum it up: Creating a decent looking web page whilst using JSPs and the Struts 2 framework.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement