How can I reuse HTML/JSP within a page?
code-reuse, jsp
Solution
Take a look at Apache tiles. Since you are working with Struts, I'm surprised you haven't found it already. It is basically a templating engine and I think fits your requirements.
The already suggested `<jsp:include>` can be used with `<jsp:param>` in order to pass variables. Like
<jsp:include file="includedFile.jsp">
<jsp:param name="username" value="jsmith" />
</jsp:include>
Actually, if only wanting to include 1 file with the common code, I'd recommend the simplicity of `<jsp:include>` over the power of Tiles.
Problem
I'm new to JSP, and I'm trying to reduce a massive amount of cut-and-pasted code. On each page in the project, there are around 25 lines of mixed JSP,Struts tags,JSTL tags, and HTML, which have been cut and pasted at various points in the page. These ~25 lines of re-used code are not even remotely similar from page to page (and there ~250 pages), but exactly the same within each page. Ultimately this (business logic) code should be moved out of the View, but doing so would be a larger project than my schedule permits at the moment, so I'm wondering if there is a simple way to re-use Mixed Tags+JSP within a page, as a temporary fix so that the code can be refactored in stages as time permits. For clarity, I am looking for a way to encapsulate code without creating a new file (/local to page scope) - i.e. it should be defined in the same page it is called from. Some have suggested that this can be done with Tiles - if that is the case, please show me how.