In java/struts/jsp world, is there something like the ASP.NET custom user control, a piece of UI with back end code that performs a specific logic, and can be pulled and used in another place (for example something like the login control).
2 Answers
The current Java EE API offers JSF 2.0 on Facelets for this. Note that Struts(2) is actually a competitor to JSF and that JSP is a view technology like ASP, not a MVC framework. As per Java EE 6 / JSF 2.0, JSP is been replaced by Facelets as the default view technology.
On top of the basic JSF implementation you can choose from a lot of "rich" component libraries which adds an extra CSS and Ajax sausage, for example PrimeFaces (showcase) and OpenFaces (showcase).
See also:
What you are after is called tag files in JSP. I found that they are not as easy to learn and use as .NET user controls.
You can use them similarly to user controls .NET.
workflow is like this.
- Create a tag file in web-inf/tags/AtillaTagLibrary/DropDownList.tag
reference your tag file in your jsp file like below
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags/AtillaTagLibrary"%>
Use your tag file like normal jsp tag.
<ct:DropDownList />
This tag files can get attribute values from outside like user controls.

- 14,339
- 3
- 49
- 69