如何使用TagExtraInfo验证动态自定义JSP标记属性?

时间:2022-11-26 10:38:39

I have created custom JSP tag and it`s working fine but having problem in attrib validation.

我已经创建了自定义JSP标记,它工作正常,但在attrib验证方面存在问题。

<tt:qu userName='<%= request.getParameter("Username") %>'/>

public class TEI extends TagExtraInfo {
public boolean isValid( TagData tagData ) {


    String jdriver = (String) tagData.getAttribute("userName");
//error at this line.

but getting error

但是得到错误

java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String tag.TEI.isValid(TEI.java:12)

java.lang.ClassCastException:java.lang.Object无法强制转换为java.lang.String tag.TEI.isValid(TEI.java:12)

2 个解决方案

#1


0  

If this is happening on the server, you need to figure what the type really is. If it isn't a String, you can't cast it as one.

如果在服务器上发生这种情况,您需要确定类型的真实情况。如果它不是String,则不能将其强制转换为String。

#2


0  

String jdriver = (String) tagData.getAttribute("userName").toString();

String jdriver =(String)tagData.getAttribute(“userName”)。toString();

just call the toString method on object and assign to string

只需在对象上调用toString方法并赋值给string

#1


0  

If this is happening on the server, you need to figure what the type really is. If it isn't a String, you can't cast it as one.

如果在服务器上发生这种情况,您需要确定类型的真实情况。如果它不是String,则不能将其强制转换为String。

#2


0  

String jdriver = (String) tagData.getAttribute("userName").toString();

String jdriver =(String)tagData.getAttribute(“userName”)。toString();

just call the toString method on object and assign to string

只需在对象上调用toString方法并赋值给string