pierreonthenet
pierreonthenet

Reputation: 165

Where is the "jsp" taglib TLD?

In a special case, I need to make the same as <jsp:useBean in Java class.

It sounds like using org.apache.commons.beanutils.BeanUtils.cloneBean(Object bean) will do the work.

But what is driving me crazy is that I can't find the TLD associated to <jsp: tags, nor the class used by <jsp:useBean.

Even <short-name>jsp</short-name> on Google gives me nothing. The JSP specs I found makes me believe that it's not a tag like the others and that the code behind <jsp:useBean is in Java's core.

Am I right? Have I missed something?

Upvotes: 1

Views: 503

Answers (4)

rickz
rickz

Reputation: 4474

If your needs are simple for the bean, then you can just add code directly to your JSP. To see what I mean, look at the Servlet that was generated from your JSP. Every JSP is translated to a Servlet. For example, consider the following JSP.

    <jsp:useBean id="myList" class="java.util.ArrayList"/>
    ${myList.add("My first element")}
    <%myList.add("My second element");%>
    ${myList}

The translation(in Tomcat's work folder) is

      java.util.ArrayList myList = null;
  myList = (java.util.ArrayList) _jspx_page_context.getAttribute("myList", jakarta.servlet.jsp.PageContext.PAGE_SCOPE);
  if (myList == null){
    myList = new java.util.ArrayList();
    _jspx_page_context.setAttribute("myList", myList, jakarta.servlet.jsp.PageContext.PAGE_SCOPE);
  }
  out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${myList.add(\"My first element\")}", java.lang.String.class, (jakarta.servlet.jsp.PageContext)_jspx_page_context, null));
    myList.add("My second element");
  out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${myList}", java.lang.String.class, (jakarta.servlet.jsp.PageContext)_jspx_page_context, null));

The useBean action tag just creates a scripting variable and sets a scoped variable. You can do that without any special tag. The following JSP does the same thing.

<%@ page import="java.util.ArrayList"%>
<%
    ArrayList myList2 = new ArrayList();
    myList2.add("one");
    pageContext.setAttribute("myList2", myList2);
%>
${myList2}
<%=myList2%>

Upvotes: 1

Samuel Marchant
Samuel Marchant

Reputation: 330

<jsp:useBean> is actually "a JSP server markup tag" "the server knows in a JSP specification server", the "tags" you are thinking of are standard tag library c: f: are resources that use a TLD Tag Library Descriptor (stored in a jar package to be loaded as a resource) and are from the original "custom tag" API system.

Custom tags do not need to be in a .jar, unjared they must be put in /webapplication/WEB-INF/tags/ often associated with non programmatic tags that operate like an include markup file. jar packaged tags are in a folder structure /webapplication*/META-INF/tags/* any tags wherever they reside require to be named to their full path in an XML markup like .tld file in the top directory of the package.

Upvotes: 1

Roman C
Roman C

Reputation: 1

There's no TLD for <jsp: elements in the JSP page. These elements are part of the JSP language. With this language you can create JSP pages but if you need to use custom TLDs like JSTL then you should use taglib directive.

What is interesting in JSP: it's called now Jakarta Server Pages. You can read more about this in the article What is JSP? Introduction to Jakarta Server Pages.

One of the original Java web technologies, JSP is still widely used with servlets and JSTL. Here's how to use Jakarta Server Pages to build dynamic web pages that connect to the Java back end.

Upvotes: 1

Pao
Pao

Reputation: 843

<jsp:useBean> is an action tag and not part of a tag library, cf. https://en.wikipedia.org/wiki/Jakarta_Server_Pages#Syntax, scroll down to "Additional Tags".

The code probably was part of J2EE back in the day or is in the servlet containers. Today it apparently is an eclipse project: https://projects.eclipse.org/projects/ee4j.jsp.

Upvotes: 1

Related Questions