解决Struts2.2.20版本的标签不支持style属性的问题
我先把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属性的问题的更多相关文章
- 让arclist标签也支持currentstyle属性 完美解决
1.查找到: $channelid = $ctag->GetAtt('channelid'); 在下面插入:$currentstyle = $ctag->GetAtt('currentst ...
- dede织梦 arclist标签完美支持currentstyle属性
由于客户需求,所以进行对文章的arclist标签进行设置当前样式(currentstyle),修改前记得备份. dede版本v5.7sp 找到PHP修改: include/taglib/arclist ...
- 在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题
首先在VSCode中打开一个HTML文件 然后点右下角的“选择语言模式” 然后点击配置HTML语言的基础设置 然后在打开的界面中(右侧) 输入如下代码 { "editor.quickSugg ...
- background低版本安卓浏览器不支持复合属性,要分开写
background:url("http://..../xxx.jpg") no-repeat center/cover; 这种复合形式在有些低端安卓浏览器中不支持,最好分开写: ...
- 解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found
解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found 异常信息: The Struts dispatcher cannot be fou ...
- struts2的s:iterator 标签 详解
s:iterator 标签有3个属性:value:被迭代的集合id :指定集合里面的元素的idstatus 迭代元素的索引1:jsp页面定义元素写法 数组或list <s:iterator ...
- 框架学习之Struts2(四)---拦截器和标签
一.拦截器概述 1.1 在struts2框架中封装了很多功能,struts2里面封装的功能都是在拦截器里面,struts2里面又很多拦截器,但不是每次这些拦截器都执行,每次执行型默认的拦截器. 默认拦 ...
- mysql-5.7.20 版本的 mysql-group-replication 可用性测试报告
一.喜迎 mysql-5.7.20 事实上mysql-group-replication 功能是在mysql-5.7.17这个版本上引入的,它实现了mysql各个结点间数据强一致性, 这个也成为了我 ...
- struts2的s:iterator 标签 详解<转>
struts2的s:iterator 可以遍历 数据栈里面的任何数组,集合等等 以下几个简单的demo: s:iterator 标签有3个属性: value:被迭代的集合 id : ...
随机推荐
- 【HDU】I love sneakers!(分组背包)
看了许多的题解,都有题目翻译,很不错,以后我也这样写.直接翻译样例: /*鞋子的数量N[1, 100]; 拥有的金钱M[1, 1w]; 品牌数目[1, 10]*/ /*以下四行是对于每双鞋的描述*/ ...
- 【转】YUV格式&像素
一幅彩色图像的基本要素是什么? 说白了,一幅图像包括的基本东西就是二进制数据,其容量大小实质即为二进制数据的多少.一幅1920x1080像素的YUV422的图像,大小是1920X1080X2=4147 ...
- mysql插入数据时,中文乱码
MySQL 插入数据时,中文乱码问题的解决(转) 当向 MySQL 数据库插入一条带有中文的数据形如 insert into employee values(null,'张三','female','1 ...
- Class的生命周期
之前的<JVM类载入机制-ClassLoader>和<初探JVM-ClassLoader源代码>,仅仅是讨论了Class的载入部分,如今来纵观一下整个Class的生命周期. C ...
- DOS命令大全--具体解释
在Linux和Windows下都能够用nslookup命令来查询域名的解析结果 DOS命令大全一)MD--建立子文件夹 1.功能:创建新的子文件夹 2.类型:内部命令 3.格式:MD[盘符:][路径名 ...
- Android 自定义UI--指南针
有了之前的基础,下面开始实现一个简单的指南针.首先来看一下效果图, 我们可以粗略将这个指南针分为三个部分,一是圆形背景,二是刻度,三是文本.那么在写代码的时候,就可以声明三个Paint画笔来画以上三个 ...
- 有关android 应用的plugin框架调研
1. 借助android提供的shareduserid属性使多个不同的apt共用一个userid,以扫除权限壁垒,获取插件context,继而获取view并加载插件.这种方式是建立在已经安装完成的ap ...
- python-文件压缩和解压
import tarfile #压缩 tar = tarfile.open('your.tar','w') tar.add('ooo.xml',arcname='ooo.xml') tar.close ...
- 什么是系统平均负载(Load average)
一.什么是系统平均负载(Load average)? 在Linux系统中,uptime.w.top等命令都会有系统平均负载load average的输出,那么什么是系统平均负载呢? Load Aver ...
- 一个简单的ajax对象
function ajax(options) { //请求参数 options = { //类型 type: options.type || "Post", //地址 url: o ...