开发者

Is there something like ASP.NET web user controls in Java/struts/jsp

In java/struts/jsp worl开发者_Python百科d, 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).


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 is the mainstream Java alternative to ASP.NET?
  • What is the difference between JSP, Servlet and JSF?
  • Java EE 6 tutorial - chapters 4-10
  • Coreservlets.com JSF 2.0 tutorial


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.

  1. Create a tag file in web-inf/tags/AtillaTagLibrary/DropDownList.tag
  2. reference your tag file in your jsp file like below

    <%@ taglib prefix="ct" tagdir="/WEB-INF/tags/AtillaTagLibrary"%>
    
  3. Use your tag file like normal jsp tag.

    <ct:DropDownList  />
    

This tag files can get attribute values from outside like user controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜