jsp中的自定义标记没有响应

时间:2022-11-26 10:34:00

I am facing problem while using custom tags in jsp. Application is running well, but tag is not responding. My Code is:

我在jsp中使用自定义标签时遇到问题。应用程序运行良好,但标签没有响应。我的代码是:

this is my index.jsp and this is working. *index.jsp*

这是我的index.jsp,这是有效的。 * *的index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/MyTagLib" prefix="mtl"%>
<!DOCTYPE html>
<html>
   <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
       your code is:<mtl:MyTagClass input="GoodMorning" start="1" end="6"/>
    </body>
</html>

this is Tag library *MyTagLib.tld*

这是Tag library * MyTagLib.tld *

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>mtl</short-name>
  <uri>/WEB-INF/MyTagLib</uri>
   <tag>
    <name>MyTagClass</name>
    <tag-class>MyPack.MyTagClass</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>input</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
     <type>java.lang.String</type>
    </attribute>
    <attribute>
       <name>start</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
      <type>java.lang.String</type>
    </attribute>
    <attribute>
      <name>end</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
      <type>java.lang.String</type>
    </attribute>
  </tag>
</taglib>

following is tag handler *MyTagClass.java*

以下是标记处理程序* MyTagClass.java *

package MyPack;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class MyTagClass extends SimpleTagSupport {
    private String input=null;
    private String start=null;
    private String end=null;
  public MyTagClass(){}
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();

        try {
            JspFragment f = getJspBody();
            if (f != null) {
                f.invoke(out);
                out.println("input.substring(start,end)");
           }
} catch (java.io.IOException ex) {
           throw new JspException("Error in MyTagClass tag", ex);
       }
    }

    public void setInput(String input) {
        this.input = input;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public void setEnd(String end) {
        this.end = end;
    }

}

n dis is web.xml *web.xml*

n dis是web.xml * web.xml *

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <jsp-config>
        <taglib>
             <taglib-uri>/WEB-INF/MyTagLib</taglib-uri>
            <taglib-location>/WEB-INF/MyTagLib.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>

please help

1 个解决方案

#1


0  

i suggest to refer the following link better understanding for customer tag implementation process Demo

我建议参考以下链接更好地了解客户标签实施过程演示

#1


0  

i suggest to refer the following link better understanding for customer tag implementation process Demo

我建议参考以下链接更好地了解客户标签实施过程演示