我先把Exception错误信息贴出来:org.apache.jasper.JasperException: /WEB-INF/jsp/topicAction/addUI.jsp (line: 40, column: 0) Unable to find setter method for attribute: style

通过Exception定位的源代码是:

通过提示我们大概能知道是因为找不到style属性的setter方法,可这个标签是struts2封装的HTML原生标签,但style属性在HTML里使用是完全没问题的,由此我想到可能是struts2封装的问题,于是乎找到struts关于UI标签的源码。如下:

public class AbstractUITagBeanInfo extends SimpleBeanInfo {
private static final Logger LOG =
LoggerFactory.getLogger(AbstractUITagBeanInfo.class);
public PropertyDescriptor[] getPropertyDescriptors() {
try {
List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
// Add the tricky one first
Method setter = AbstractUITag.class.getMethod("setCssClass", String.class);
descriptors.add(new PropertyDescriptor("class", null, setter));
descriptors.add(new PropertyDescriptor("cssClass", null, setter)); for (Field field : AbstractUITag.class.getDeclaredFields()) {
String fieldName = field.getName();
if (!"dynamicAttributes".equals(fieldName)) {
String setterName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
setter = AbstractUITag.class.getMethod(setterName, String.class);
descriptors.add(new PropertyDescriptor(fieldName, null, setter));
}
} PropertyDescriptor[] array = new PropertyDescriptor[descriptors.size()];
return descriptors.toArray(array);
} catch (Exception e) {
// This is crazy talk, we're only doing things that should always succeed
LOG.fatal("Could not construct bean info for AbstractUITag. This is very bad.", e);
return null;
}
}
}
 

发现 AbstractUITagBeanInfo中确实没有对style属性的解析处理代码,于是我去官网下载了更新版本的struts(struts2.3.21),查看源代码 惊喜的发现它解决了这个问题。我把它的这部分代码贴出来:

descriptors.add(new PropertyDescriptor("class", null, classSetter));      

descriptors.add(newPropertyDescriptor("cssClass", null, classSetter));   

descriptors.add(new PropertyDescriptor("style", null, styleSetter));  //这里是相对于struts2.3.20增加的对style属性的解析

descriptors.add(new PropertyDescriptor("cssStyle", null, styleSetter));   //这里是相对于struts2.3.20增加的对cssStyle属性的解析
 

那么问题来了,我们要怎么解决这个问题呢,我的做法是在工程中新建一个和AbstractUITagBeanInfo这个类同名同包的文件(包名和类名都要相同),再把struts2.3.21版本中这个类的源代码拷贝过来,这样新的类就会覆盖原来的那个标签处理类。当然你也可以找到这个类所在的jar包删掉再把新版本中的这个jar包加进来。

注:这个不仅是针对<s:form/>标签,所有有style属性的标签如<s:textfiled/>等都会出现这个问题。

版权声明:本文为博主原创文章,未经博主允许不得转载。

解决Struts2.2.20版本的标签不支持style属性的问题的更多相关文章

  1. 让arclist标签也支持currentstyle属性 完美解决

    1.查找到: $channelid = $ctag->GetAtt('channelid'); 在下面插入:$currentstyle = $ctag->GetAtt('currentst ...

  2. dede织梦 arclist标签完美支持currentstyle属性

    由于客户需求,所以进行对文章的arclist标签进行设置当前样式(currentstyle),修改前记得备份. dede版本v5.7sp 找到PHP修改: include/taglib/arclist ...

  3. 在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题

    首先在VSCode中打开一个HTML文件 然后点右下角的“选择语言模式” 然后点击配置HTML语言的基础设置 然后在打开的界面中(右侧) 输入如下代码 { "editor.quickSugg ...

  4. background低版本安卓浏览器不支持复合属性,要分开写

    background:url("http://..../xxx.jpg") no-repeat center/cover; 这种复合形式在有些低端安卓浏览器中不支持,最好分开写: ...

  5. 解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found

    解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found 异常信息: The Struts dispatcher cannot be fou ...

  6. struts2的s:iterator 标签 详解

    s:iterator 标签有3个属性:value:被迭代的集合id   :指定集合里面的元素的idstatus 迭代元素的索引1:jsp页面定义元素写法 数组或list <s:iterator ...

  7. 框架学习之Struts2(四)---拦截器和标签

    一.拦截器概述 1.1 在struts2框架中封装了很多功能,struts2里面封装的功能都是在拦截器里面,struts2里面又很多拦截器,但不是每次这些拦截器都执行,每次执行型默认的拦截器. 默认拦 ...

  8. mysql-5.7.20 版本的 mysql-group-replication 可用性测试报告

    一.喜迎 mysql-5.7.20  事实上mysql-group-replication 功能是在mysql-5.7.17这个版本上引入的,它实现了mysql各个结点间数据强一致性, 这个也成为了我 ...

  9. struts2的s:iterator 标签 详解<转>

    struts2的s:iterator 可以遍历 数据栈里面的任何数组,集合等等 以下几个简单的demo: s:iterator 标签有3个属性:     value:被迭代的集合     id   : ...

随机推荐

  1. 按每k个结点反转链表

    //按每k个结点反转链表 Node* turn_k(Node* head,int n,int k) { Node* p=head; ;t<k;t++) p=p->next; //为了获取最 ...

  2. Web开发之RSET API

    REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(http://zh.wikipedia.org/zh-cn/Web),具体的我就 ...

  3. Exchange Server 2010/2013架构改变

    Exchange Server 2010架构 Exchange Server 2013架构

  4. Annotation(四)——Struts2注解开发

    Hibernate和Spring框架的开发前边总结了,这次看一下流行的MVC流程框架Struts2的注解开发吧.Struts2主要解决了从JSP到Action上的流程管理,如何进行Uri和action ...

  5. <s:iterator> 序号

    <s:iterator />的序号,解决这个问题有两种办法. 方法一:通过set标签实现: <s:set name="a" value=1/> <s: ...

  6. IOS UIlabel设置文本距离边框距离

    自定义UILabel 继承 UILabel 重写drawTextInRect 方法具体如下: CGRect rect = CGRectMake(rect.origin.x + 5, rect.orig ...

  7. pyqt一个小例子

    # -*- coding: utf-8 -*- __author__ = 'Administrator' from PyQt4 import Qt,QtCore,QtGui import sys,ra ...

  8. Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config.

    [问题] Eclipse[Ubuntu14.04]中启动Tomcat Server[7.0.55]的时候出现错误例如以下: [解决方法] 1.将下边的Servers中的server[Tomcat v7 ...

  9. java foreach循环为什么不能赋值

    直接上代码 public class test4 { public static void main(String args[]){ int [] a=new int[3]; for(int j:a) ...

  10. AIX 常用命令和知识

      BOOTLIST:#bootlist -m normal -o (查看bootlist)#bootlist -m normal (设置bootlist为空,谁要在我机器上执行我就要哭了)#boot ...