Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instance class within Tag File without scriplet?  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all and thousand thanks in advance

My architecture is composed by: jsp-tag handler-delegate-session-entity-db
I was thinking to come near to jsp2.0 (el-jstl1.2). Is possible to instance one class into Tag File without to use an scriplet and if yes how give to class instanced some parameters?

My Tag File's example is:

<%@ taglib prefix="c" uri="" %>
<%@ variable name-given="strout" description="Parametro in uscita" variable-class="java.lang.String" scope="AT_END" %>
<%@ attribute name="strin" required="true" type="java.lang.String" description="Parametro in ingresso" %>
<%@ tag isELIgnored="false" %>
<%@ tag import="java.util.*" %>
<%@ tag import="javax.servlet.jsp.*" %>
<%@ tag import="javax.servlet.*" %>
<%@ tag import="test.*" %>

String a = (String)pageScope.getAttribute("strin");
TestDelegate testDelegate = new TestDelegate();
String str = testDelegate.getNewName(a);%>

<c:set var="strout" value="${str}"/>


In this way don't work. How can make?
Author and ninkuma
Posts: 66425
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bartender: please move this to the JSP forum.

Welcome to the Ranch, Angelo.

You may be thinking about the problem not-so-correctly. If you are trying to convert an existing application from JSP 1.x to JSP 2.0, there are frequently some off-page changes that need to take place. Please read the JavaRanch Journal article that I wrote on this very subject.

To be specific, as you have discovered, scriplets are not allowed in tag files. And since your example includes a call to a method that expects a parameter, you cannot use the EL which expects bean-patterned classes.

You may need to take a step back and figure out what you are trying to accomplish and rework it. Or, if you need to do "general Java" type things in your tag, you may just need to use a Java-based tag handler rather than a tag file.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!