Issue while calling a static Method in jsp

CoreThought

While calling the static method of a Java class from tld , I am facing some issues like while running the jsp file it always display this ${test:concat("java")} as an output it's not even calling the java class.

index.jsp File

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="test" uri="/WEB-INF/SubstrDescriptor.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>JSP Custom Taglib example: Substr function</title>
</head>
${test:concat("java")}
</html>

SubstrDescription.tld

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">

    <tlib-version>2.0</tlib-version>

    <function>
        <name>concat</name>
        <function-class>java4s.Demo</function-class>
        <function-signature>java.lang.String doMyStuff( java.lang.String )
        </function-signature>
    </function>
</taglib>

Demo.java

package java4s;

public class Demo {

     public static String doMyStuff( String myparam )
        {
         System.out.println(myparam);
           return myparam;
        }

}
Braj

Make few change as mentioned below and check it again.

  • Define <uri>SubstrDescriptor</uri> in tld.
  • Use <%@ taglib prefix="test" uri="SubstrDescriptor"%> in JSP.

Please have a look at similar post How to call a static method in JSP/EL? that might help you for better understanding.

JSP:

<%@ taglib prefix="test" uri="SubstrDescriptor"%>
<body>
     ${test:concat("java")}
</body>

SubstrDescription.tld:

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">

    <tlib-version>2.0</tlib-version>    
    <uri>SubstrDescriptor</uri> 
    <function>
        <name>concat</name>
        <function-class>java4s.Demo</function-class>
        <function-signature>java.lang.String doMyStuff( java.lang.String )
        </function-signature>
    </function>
</taglib>

Project structure:

WebContent
          |
          |__WEB-INF
          |         |
          |         |__SubstrDescription.tld
          |         |__web.xml
          |
          |__index.jsp

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What is the syntax for calling a static typed method while doing a import static?

From Dev

Internal Server error while calling an Java method from JSP

From Dev

Issue with calling static template method inside a template class

From Java

Calling generic static method locally while omitting class name

From Java

Calling a java method in jsp

From Dev

Facing issue while calling post method from angular

From Java

calling static method in java

From Java

Calling the instance of a static method

From Java

Calling static method in python

From Java

Calling static method on a class?

From Dev

Method calling issue

From Dev

Issue with method calling

From Dev

Method calling and display issue

From Dev

Method Calling Syntax Issue

From Dev

Issue with a static recursive method

From Dev

Fix Static Method issue

From Dev

Calling non static method in static method

From Dev

Calling method onClick of Jsp form Jsp

From Java

Why cannot use this while calling static interface method from default interface method?

From Dev

Uncaught type error & Uncaught reference error while calling EXTJS method from JSP

From Dev

Issue while calling function in databricks

From Dev

Calling static method on type alias

From Dev

Idiomatic way of calling a static method

From Dev

Efficiency of java static method calling

From Dev

C++ calling a static method

From Dev

Calling static method in main part

From Dev

Method Calling (Static/Non-Static)

From Dev

Calling a non static method from a in a static context

From Dev

Issue calling method in short example