Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jsp中解释动态属性的问题_Java_Jsp_Custom Tags - Fatal编程技术网

Java Jsp中解释动态属性的问题

Java Jsp中解释动态属性的问题,java,jsp,custom-tags,Java,Jsp,Custom Tags,我试图在Jsp中处理动态属性,但没有得到显示响应 以下是JSP代码: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="mine" uri="DiceFunctions" %> <html><body> <mine:advice suggest="yo haa haa" > </mine:advice&g

我试图在Jsp中处理动态属性,但没有得到显示响应

以下是JSP代码:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="mine" uri="DiceFunctions" %>


<html><body>

<mine:advice  suggest="yo haa haa" >

</mine:advice>
</body></html>

位于WEB-INF文件夹中的TLD文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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>1.2</tlib-version>
<jsp-version>2.0</jsp-version>
<uri>DiceFunctions</uri>

<tag>

<name>advice</name>
<tag-class>foo.AdvisorTagHandler</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>optionList</name>
<type>java.util.List</type>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
</attribute>
<attribute>
<name>size</name>
<required>false</required>
</attribute>
<dynamic-attributes>true</dynamic-attributes>

</tag>

1.2
2
骰子函数
建议
foo.AdvisorTagHandler
无脚本
选择者
java.util.List
假的
真的
名称
假的
大小
假的
真的

和标记处理程序类:

package foo;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import javax.servlet.jsp.*;
import java.util.*;

public class AdvisorTagHandler extends TagSupport implements DynamicAttributes {



private Map<String,Object> tagAttrs=new HashMap<String,Object>();

public int doStartTag() throws JspException{
//movieCounter=0;
try{


for(String attr: tagAttrs.keySet())
{
String attrd=String.format("%s='%s'",tagAttrs.get(attr));

pageContext.getOut().print(attrd);
}

}
catch(Exception e)
{
}

return SKIP_BODY;
}

public void setDynamicAttribute(String uri, String name, Object value){

tagAttrs.put(name,value);
}
public int doEndTag() throws JspException{
return EVAL_PAGE;
}
package-foo;
导入javax.servlet.jsp.JspException;
导入javax.servlet.jsp.tagext.*;
导入java.io.*;
导入javax.servlet.jsp.*;
导入java.util.*;
公共类AdvisorTagHandler扩展标记支持实现动态属性{
私有映射tagAttrs=newhashmap();
public int doStartTag()抛出JSPEException{
//movieCounter=0;
试一试{
for(字符串attr:tagAttrs.keySet())
{
String attrd=String.format(“%s='%s',tagAttrs.get(attr));
pageContext.getOut().print(attrd);
}
}
捕获(例外e)
{
}
返回跳过单元体;
}
public void setDynamicAttribute(字符串uri、字符串名称、对象值){
tagAttrs.put(名称、值);
}
public int doEndTag()抛出JspException{
返回评估页面;
}
要显示动态属性值,我需要做哪些修改


提前感谢。

您可以在空的catch块中放置一些代码,看看会发生什么…

您可以在空的catch块中放置一些代码,看看会发生什么…

这一行有一个问题:

String attrd = String.format("%s='%s'", tagAttrs.get(attr));
指定两个字符串参数,但只提供一个

这样的方法应该更有效:

try {
  for (Map.Entry<String, Object> attr : tagAttrs.entrySet()) {
    String attrd = String.format("%s='%s'", attr.getKey(), attr
        .getValue().toString());
    pageContext.getOut().print(attrd);
  }
} catch (IOException e) {
  throw new JspException(e);
}
试试看{
对于(Map.Entry attr:tagAttrs.entrySet()){
String attrd=String.format(“%s=“%s”,attr.getKey(),attr
.getValue().toString());
pageContext.getOut().print(attrd);
}
}捕获(IOE异常){
抛出新的JSPEException(e);
}

这一行有一个问题:

String attrd = String.format("%s='%s'", tagAttrs.get(attr));
指定两个字符串参数,但只提供一个

这样的方法应该更有效:

try {
  for (Map.Entry<String, Object> attr : tagAttrs.entrySet()) {
    String attrd = String.format("%s='%s'", attr.getKey(), attr
        .getValue().toString());
    pageContext.getOut().print(attrd);
  }
} catch (IOException e) {
  throw new JspException(e);
}
试试看{
对于(Map.Entry attr:tagAttrs.entrySet()){
String attrd=String.format(“%s=“%s”,attr.getKey(),attr
.getValue().toString());
pageContext.getOut().print(attrd);
}
}捕获(IOE异常){
抛出新的JSPEException(e);
}
我在catch块中尝试了e.getMessage()或e.printStackTrace()方法,但仍然没有得到响应。我在catch块中尝试了e.getMessage()或e.printStackTrace()方法,但仍然没有得到响应。