在用Struts上传文件时,遇到了javax.servlet.ServletException: BeanUtils.populate异常

今天在做项目上传图片时候遇到一下错误:
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:34)
root cause

org.apache.commons.beanutils.ConversionException: Cannot assign value of type 'java.lang.String' to property 'file' of type 'org.apache.struts.upload.FormFile'
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:422)
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1733)
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:34)
后经过多方查找BeanUtils.populate错误,然后发现一下文章
我的ActionServlet并没有用到BeanUtils这些工具类。后来仔细检查代码发现是在jsp文件里的form忘了加enctype="multipart/form-data"; 了。所以写程序遇到错误或异常应该从多方面考虑问题存在的可能性,想到系统提示信息以外的东西。

----------------------------------------------------------------------------------------------------------------------------

1. 定义Action后, 如果指定了name, 那么必须要定义一个与它同名的FormBean才能进行form映射.

2. 如果定义Action后, 提交页面时出现 "No input attribute for mapping path..." 错误, 则需要在其input属性中定义转向的页面.

3. 如果插入新的数据时出现 "Batch update row count wrong:..." 错误, 则说明XXX.hbm.xml中指定的key的类型为原始类型(int, long),

因为这种类型会自动分配值, 而这个值往往会让系统认为已经存在该记录, 正确的方法是使用java.lang.Integer或java.lang.Long对象.

4. 如果插入数据时出现 "argument type mismatch" 错误, 可能是你使用了Date等特殊对象, 因为struts不能自动从String型转换成Date型,

所以, 你需要在Action中手动把String型转换成Date型.

5. Hibernate中, Query的iterator()比list()方法快很多.

6. 如果出现 "equal symbol expected" 错误, 说明你的strtus标签中包含另一个标签或者变量, 例如:

<html:select property="test" onchange="<%=test%>"/>

或者

<html:hidden property="test" value="<bean:write name="t" property="p"/>"/>

这样的情况...
-----------------------------------------------------------------------------------------------
通过在我上传的jsp页面里面添加了enctype="multipart/form-data"标签。问题得到解决。
ENCTYPE="multipart/form-data"用于表单里有图片上传。

<form name="userInfo" method="post" action="first_submit.jsp" ENCTYPE="multipart/form-data">
表单标签中设置enctype="multipart/form-data"来确保匿名上载文件的正确编码。
如下:
<tr>
<td height="30" align="right">上传企业营业执照图片:</td>
<td><INPUT TYPE="FILE" NAME="uploadfile" SIZE="34" onChange="checkimage()"></td>
</tr>
就得加ENCTYPE="multipart/form-data"。


表单中enctype="multipart/form-data"的意思,是设置表单的MIME编码。默认情况,这个编码格式是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整的传递文件数据,进行下面的操作.
enctype="multipart/form-data"是上传二进制数据; form里面的input的值以2进制的方式传过去。
form里面的input的值以2进制的方式传过去,所以request就得不到值了。也就是说加了这段代码,用request就会传递不成功,取表单值加入数据库时,用到下面的:

SmartUpload su = new SmartUpload();//新建一个SmartUpload对象

su.getRequest().getParameterValues();取数组值

su.getRequest().getParameter( );取单个参数单个值
STM32F103串口接收中断:USART_IT_IDLE和USART_IT_RXNE区别 2:如果是大于1个byte的数据,在不用DMA的情况下,同时使能USART_IT_RXNE,USART_IT_IDLE中断,每收到一个字节在中断中把数据存到缓存中,待收到USART_IT_IDLE中断时,收完整帧数据,然后再解析处理数据。比如:如上图在初始化时,同时开启了两个中断,如果传送8个字节的数据,就会产生8个USART_IT_RXNE,和1个USART_IT_IDLE中断。(如果接收到数据,在1个byte的时间内,没有收到新数据,就认为是数据传送完成,产生空闲USART_IT_IDLE中断) 阅读详情

相关推荐

避坑指南:MTK平台Widevine L1密钥安装全流程详解(含SP META工具使用与Log分析)

本文详细解析了MTK平台实现Widevine L1认证的全流程,涵盖密钥申请、格式转换、安全烧录等关键步骤,特别针对Trustonic TEE环境下的SP META工具使用与日志分析提供实用指南。帮助开发者规避常见错误,确保DRM密钥安全部署,满足高端内容保护需求。

weixin_27219587的博客 475

javax.servlet.ServletException: BeanUtils.populate

type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: BeanUtils.popu

westonduo的专栏 1159

ZYNQ出现问题及解决办法汇总(一直更新)

问题目录使用软件及开发板版本一,vitis在build project时卡住。二,Could not find FPGA device on the board for connection 'Local'三,FPGA configuration failed:DONE PIN is not high四,Could not find ARM device on the board for connection 'Local' 使用软件及开发板版本 开发板:MZ7XA-7020 软件:vitis2020.2(

qq_45057368的博客 1万+

JavaWeb使用BeanUtils.populate()报错并且debug调试为null

JavaWeb使用BeanUtils.populate()报错并且debug调试为null

weixin_46055410的博客 566

探索niri:让你的Linux桌面布局无拘无束

niri是一款基于Wayland的滚动平铺合成器,采用创新的窗口管理方式。它将窗口排列为向右无限延伸的条目,支持独立显示器布局和动态垂直工作区,确保多任务操作流畅性。核心功能包括概要视图、截图界面、屏幕投射、手势操作、窗口分组等,并支持自定义布局和动画效果。niri具备良好的稳定性,兼容xwayland-satellite工具,灵感来自PaperWM但突破了GNOME限制。该项目为追求高效桌面管理的用户提供了全新解决方案,欢迎加入社区交流体验。

weixin_44626085的博客 1815

TPS65987D USB PD控制器:从原理到实战的完整设计指南

USB PD(Power Delivery)协议是USB Type-C接口实现高功率快充和数据传输的核心技术标准。其工作原理基于CC(Configuration Channel)引脚的双相标记编码(BMC)通信,通过协商电压和电流,实现高达100W的功率传输。这项技术的核心价值在于统一了充电标准,简化了设备间的互操作性,广泛应用于笔记本电脑、移动电源、扩展坞等设备。TPS65987D作为一款高度集成的USB PD控制器,将复杂的协议处理、电源路径管理和多重保护电路集成于单芯片,显著降低了设计复杂度。通过其可

weixin_30983965的博客 337

java中三种可能导致异常的情况_java中常见的几种异常

异常javax.servlet.jsp.JspException: Cannot retrieve mapping for action/Login(/Login是你的action名字)可能原因action没有再struts-config.xml 中定义,或没有找到匹配的action,例如在JSP文件中使用action="Login.do".将表单提交给Login.do处理,如果出现上述异常,请...

weixin_39633089的博客 850

告别手动复制粘贴:3种高效合并Excel表格的方法对比(含代码)

本文对比了VBA、Power Query和Python三种高效合并Excel表格的方法,并提供了可直接运行的代码。针对不同数据量、更新频率和技术背景,详细分析了各方案的优缺点与适用场景,帮助读者告别低效的手动操作,实现自动化数据整合。

weixin_29057237的博客 440

严重: Servlet.service() for servlet

Spring MVC 严重: Servlet.service() for servlet [FrankDemo] in context with path [/FrankDemo] threw exception [Could not resolve view with name '/frank' in servlet with name 'SDS'] with root causejava...

frank1998819 1万+

使用 Tesseract 在 C# 中进行光学字符识别(OCR)

你可以根据需要对 Tesseract 进行自定义配置,例如设置识别的分辨率、识别模式等。// 只识别数字// 设置自定义变量本文只讲述了简单的使用方法,未涉及字库训练,识别的准确率与训练的字库有关。

仰望星空的博客 4730

RML2018.01a数据集的读取与使用

基于深度学习的自动调制识别

QAQIknow的博客 1万+

javax.servlet.ServletException: BeanUtils.populate 解决方案【转载】

在用Struts上传文件时,遇到了javax.servlet.ServletException: BeanUtils.populate异常。我的ActionServlet并没有用到BeanUtils这些工具类。感觉很奇怪。后来仔细检查代码发现是在jsp文件里的form忘了加enctype="multipart/form-data" 了。加上之后,果然没有异常了。所以写程序遇到错误或异常应该从多方面

9609

2、TrustZone(内含链接)——长期学习内容

ARM系列学习路径整理,希望对大家有用。

HoneyIC的博客 231

javax.servlet.ServletException: BeanUtils.populate 解决方案

在用Struts上传文件时,遇到了javax.servlet.ServletException: BeanUtils.populate异常。我的ActionServlet并没有用到BeanUtils这些工具类。感觉很奇怪。后来仔细检查代码发现是在jsp文件里的form忘了加enctype="multipart/form-data" 了。加上之后,果然没有异常了。所以写程序遇到错误或异常应该从多方面

techyang 的专栏 (一万年太久,只争朝夕) 6215

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

常见的BeanUtils.populate异常 解决方案

今天做文件的导出遇到了 javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495) org.apache.struts.action.RequestProcessor.processPopulate(Request...

umluser12的博客 4539

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

出现javax.servlet.ServletException: BeanUtils.populate异常

exception javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) org.apache.struts.action.RequestProcessor.processPopulate(Reques

【三少爷】的专栏 1万+

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

javax.servlet.ServletException: BeanUtils.populate报错原因

环境: struts1+spring+hibernate(好落后。。) 错误关键字: javax.servlet.ServletException: BeanUtils.populate org.apache.commons.beanutils.ConversionException: No value specified for 'java.sql.Timestamp' 原因...

cblstc的博客 2603

javax.servlet.ServletException: javax.servlet.ServletException: BeanUtils.populate

javax.servlet.ServletException: javax.servlet.ServletException: BeanUtils.populate        出现这个问题的原因就是你可能在actionform表单里设置了日期的set,get方法,但却没有jsp中填写。

wdongguo的专栏 548

关于BeanUtils.populate的解决

BeanUtils.populate 在Struts开发中遇到了这个问题:javax.servlet.ServletException: BeanUtils.populate 可能原因如下:    1.JSP页面是Sing 类型的,如果actionForm里头的数据定义成别的类型,就会报这个错    2.JSP页面的字段什么写错了。    3.当上传文件有 时如果不

muzizhuben的专栏 9187

BeanUtils.populate No bean specified

<br /><br />ype Exception report<br />message<br />description The server encountered an internal error () that prevented it from fulfilling this request.<br />exceptionjavax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtil

汇集点滴 聚沙成塔 2915

java.lang.IllegalArgumentException: No bean specified和javax.servlet.ServletExcep

public class SmUserPagePropBean extends BcmsBean {     private SmUserPagePropModel smUserPagePropModel;     省略set和get方法 } 异常:    javax.servlet.ServletException: BeanUtils.populate org.apache....

Ants 189
上一篇: html导成word
下一篇: 易用的JQuery上传插件Uploadify
java_doom
博客等级 码龄20年 6粉丝 199原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值