addcompanyproduct.jsp(看注释产品图片)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>My JSP 'addcompanyproduct.jsp' starting page</title> <meta content="IE=7.0000" http-equiv="X-UA-Compatible"> <link rel="stylesheet" type="text/css" <script type="text/javascript" src="js/base(2).js"></script> <script type="text/javascript" src="js/form.js"></script> <script type="text/javascript" src="js/blockui.js"></script> <script type="text/javascript" src="js/product.js"></script> <meta name="GENERATOR" content="MSHTML 10.00.9200.16384"> </head> <body marginheight="0"> <form name="form" action="companyProductAction_addCompanyProduct" enctype="multipart/form-data"> <div class="formzone"> <div class="namezone">产品发布</div> <div class="tablezone"> <div id="notice" class="noticediv"></div> <table cellspacing="0" cellpadding="2" width="100%" align="center" border="0"> <tbody> <tr> <td height="30" width="100" align="center">产品分类</td> <td height="30"><select id="selcatid" name="companyProduct.productTypeT"> <option selected="true" value="12">鲁西黄牛</option> <option value="13">西门塔尔牛</option> <option value="14">夏洛莱牛</option> <option value="15">利木赞牛</option> <option value="16">育肥肉牛犊</option> <option value="17">荷斯坦奶牛</option> </select></td> </tr> <tr> <td height="30" width="100" align="center">产品名称</td> <td height="30"><input class="input" style="FONT-SIZE: 12px; WIDTH: 499px" maxlength="200" name="companyProduct.companyProductNameT"> <span style="color:red">* </span></td> </tr> <tr> <td height="30" width="100" align="center">产品图片</td> <td height="30"> <!-- <input class="input" style="WIDTH: 499px" type="file" name="uploadPicture"> <span style="color:red">*</span> --> <!-- <input type="file" name="uploadPicture"></td> --><td height="30"><input id="jpg" class="input" size="50" type="file" name="upload"> </td> </tr> </tbody> </table> <div id="proplist"></div> <table cellspacing="0" cellpadding="2" width="100%" align="center" border="0"> <tbody> </tbody> </table> </div> <div class="adminsubmit"> <input type="text" value="admin" name="companyProduct.editerT"> <input type="text" value="1" name="companyProduct.checkT"> <input type="text" value="1" name="companyProduct.recommandT"><input type="text" value="1" name="companyProduct.boldT"><input type="text" value="1" name="companyProduct.permissionT"> <input class="button" type="submit" value="提交" /> </div> </div> </form> </body> </html> </body> </html>
AcompanyProductAction.java(看注释addProductAction方法)
package com.xumuye.action; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.struts2.ServletActionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; import com.xumuye.bean.CompanyProduct; import com.xumuye.service.CompanyProductService; import com.xumuye.util.Page; import com.xumuye.util.PageUtil; @Controller public class CompanyProductAction extends ActionSupport { /** * */ private static final long serialVersionUID = -3190817860600835920L; // /////////////////////////////////////////////// // 成员变量///////////////////////////////////// // 注入UserService @Autowired private CompanyProductService companyProductService; private List<CompanyProduct> companyProducts; private CompanyProduct companyProduct; private int companyProductId; // 文件 private File upload; // 文件类型 private String uploadContentType; // 文件名称 private String uploadFileName; private int pageindex; private int total; Page page = new Page(); // /////////////////////////////////////////get/set方法///////////////////////////////////////// public Page getPage() { return page; } public void setPage(Page page) { this.page = page; } public int getPageindex() { if (pageindex == 0) { pageindex = 1; } return pageindex; } public void setPageindex(int pageindex) { this.pageindex = pageindex; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } public List<CompanyProduct> getCompanyProducts() { return companyProducts; } public void setCompanyProducts(List<CompanyProduct> companyProducts) { this.companyProducts = companyProducts; } public File getUpload() { return upload; } public void setUpload(File upload) { this.upload = upload; } public String getUploadContentType() { return uploadContentType; } public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public String getUploadFileName() { return uploadFileName; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public CompanyProduct getCompanyProduct() { return companyProduct; } public void setCompanyProduct(CompanyProduct companyProduct) { this.companyProduct = companyProduct; } public int getCompanyProductId() { return companyProductId; } public void setCompanyProductId(int companyProductId) { this.companyProductId = companyProductId; } // ///////////////////////////////////////Action////////////////////////////////////////////// @SuppressWarnings({ "static-access", "unchecked" }) public String findCompanyProduct() { companyProducts = companyProductService.findCompanyProduct(); page.setPagecount(companyProducts.size()); if (companyProducts.size() != 0) { companyProducts = PageUtil.fenye(companyProducts, pageindex, 1); } total = page.getPagecount(); return "findcompanyproduct"; } // public String findCompanyProductById() { // companyProduct = companyProductService // .findCompanyProductById(companyProductId); // return "findcompanyproductbyid"; // } public String findCompanyProductById() { // companyProduct = companyProductService // .findCompanyProductById(companyProductId); // return "findcompanyproductbyid"; // } public String addCompanyProduct() throws IOException { // 定义一个文件的保存的路径 String savePath = ServletActionContext.getServletContext().getRealPath( "/companyProductPicture/" + this.uploadFileName); // 打印文件保存的路径 System.out.println(savePath); // 保存文件 // 创建文件的读取上传的文件 FileInputStream fis = new FileInputStream(upload); FileOutputStream fos = new FileOutputStream(savePath); // 复制文件 IOUtils.copy(fis, fos); // 清空缓存 fos.flush(); // 关闭文件流 fos.close(); companyProduct.setPictureNameT(uploadFileName); companyProduct.setUpdateTimeT(new SimpleDateFormat("yyyy-MM-dd") .format(new Date()).toString()); companyProductService.addCompanyProduct(companyProduct); return "addcompanyproducts"; } }
struts.xml(看注释公司产品处)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!--配置struts2的常量 --> <!-- 将struts2的Action交给spring实例化 --> <constant name="struts.objectFactory" value="spring" /> <!--指定web应用的默认编码 --> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- struts2支持动态方法调用 --> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!-- struts2的开发模式,用于热部署 --> <constant name="struts.devMode" value="true" /> <package name="usermanager" namespace="/" extends="struts-default"> <!-- 1.登录 --> <action name="loginAction" class="userAction" method="login"> </action> <!-- 2.修改密码 --> <action name="loginAction" class="userAction" method="login"> </action> </package> <package name="menuManager" namespace="/" extends="struts-default"> <action name="*_*" class="{1}" method="{2}"> <!-- ///////////////////////////////////////用户管理开始/////////////////////////////////////////////////// --> <result name="loginfailure">/login.jsp</result> <result name="loginsuccess">/backgroundindex.jsp</result> <result name="finduserbyid" type="chain">userAction_updateUserPassword </result> <result name="updateuserpassword">/updatepassword.jsp</result> <!-- ///////////////////////////////////////用户管理结束/////////////////////////////////////////////////// --> <!-- ////////////////////////////////////导航菜单前台后台管理开始//////////////////////////////////////////// --> <result name="findmenus" type="chain">subMenuAction_findSubMenus </result> <result name="findSubMenus">/menuset.jsp</result> <result name="findmenubyid" type="chain">menuAction_updateMenu </result> <result name="updatemenusuccess" type="redirectAction">menuAction_findMenus </result> <result name="delmenusuccess" type="redirectAction">menuAction_findMenus </result> <result name="addmenu" type="redirectAction">menuAction_findMenus</result> <result name="findsubmenubyid" type="chain">subMenuAction_updateSubMenu </result> <result name="updatesubmenusuccess" type="redirectAction"> menuAction_findMenus </result> <result name="delsubmenusuccess" type="redirectAction">menuAction_findMenus </result> <result name="addsubmenusuccess" type="redirectAction">menuAction_findMenus </result> <result name="visitmenusuccess" type="chain">indexAction_visitSubMenus </result> <result name="visitsubmenusuccess" type="chain">indexAction_visitBottomMenus </result> <result name="visitbottommenussuccess" type="chain">indexAction_visitLogoPictures </result> <result name="visitlogopicturessuccess" type="chain">indexAction_visitCompanyInfo </result> <result name="visitcompanyinfosuccess">/indexframe.jsp </result> <!-- ////////////////////////////////////导航菜单前台后台管理结束//////////////////////////////////////////// --> <!-- ////////////////////////////////////底部导航菜单前台后台管理开始//////////////////////////////////////////// --> <result name="findbottommenus">/bottommenuset.jsp</result> <result name="addbottommenusuccess" type="redirectAction">bottomMenuAction_findBottomMenus </result> <result name="findbottommenubyid" type="chain"> bottomMenuAction_updateBottomMenu </result> <result name="updatebottommenusuccess" type="redirectAction">bottomMenuAction_findBottomMenus </result> <result name="delbottommenusuccess" type="redirectAction">bottomMenuAction_findBottomMenus </result> <!-- ////////////////////////////////////底部导航菜单前台后台管理结束//////////////////////////////////////////// --> <!-- ////////////////////////////////////商标图片上传开始//////////////////////////////////////////// --> <result name="findlogopictures">/logopicture.jsp</result> <result name="findlogopicturebyid" type="chain"> logoPictureAction_updateLogoPicture </result> <result name="updatelogopicture" type="redirectAction"> logoPictureAction_findLogoPictures </result> <!-- ////////////////////////////////////商标图片上传结束//////////////////////////////////////////// --> <!-- ////////////////////////////////////公司信息开始//////////////////////////////////////////// --> <result name="findcompanyinfo">/updatecompanyinfo.jsp</result> <result name="findcompanyinfobyid" type="chain">companyInfoAction_updateCompanyInfo </result> <result name="updatecompanyinfo" type="redirectAction">companyInfoAction_findCompanyInfo </result> <!-- ////////////////////////////////////公司信息结束//////////////////////////////////////////// --> <!-- ////////////////////////////////////公司文化开始//////////////////////////////////////////// --> <result name="findcorporateculture">/updateCorporateCulture.jsp</result> <result name="findcorporateculturebyid" type="chain">corporateCultureAction_updateCorporateCulture </result> <result name="updatecorporateculture" type="redirectAction">corporateCultureAction_findCorporateCulture </result> <!-- ////////////////////////////////////公司文化结束//////////////////////////////////////////// --> <!-- ////////////////////////////////////联系方式开始//////////////////////////////////////////// --> <result name="findcontacts">/updatecontacts.jsp</result> <result name="findcontactsbyid" type="chain">contactsAction_updateContacts </result> <result name="updatecontacts" type="redirectAction">contactsAction_findContacts </result> <result name="findcontactstoindex">/contacts.jsp </result> <!-- ////////////////////////////////////联系方式结束//////////////////////////////////////////// --> <!-- ///////////companyProductAction/////////////////////////公司产品开始//////////////////////////////////////////// --> <result name="findcompanyproduct">/productsmanage.jsp </result> <result name="addcompanyproducts">/login.jsp </result> <result name="input">/login.jsp </result> <!-- <result name="input">/error.jspcompanyProductAction_findCompanyProduct </result> --> <!-- ////////////////////////////////////公司产品结束//////////////////////////////////////////// --> </action> </package> </struts>
一个表单,里面有几个字段,出去upload这个在Action中的值,
其他的都能够保存。
加上上传产品图片的这个之后报错:
这是Myeclipse中的:
警告: Error setting expression 'upload' with value '[Ljava.lang.String;@46e91e2f' ognl.MethodFailedException: Method "setUpload" failed for object com.xumuye.action.CompanyProductAction@68e5ccce [java.lang.NoSuchMethodException: com.xumuye.action.CompanyProductAction.setUpload([Ljava.lang.String;)] at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1289) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315) at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:78) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315) at ognl.ASTProperty.setValueBody(ASTProperty.java:127) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.Ognl.setValue(Ognl.java:737) at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:218) at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:187) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:174) at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:152) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:230) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.NoSuchMethodException: com.xumuye.action.CompanyProductAction.setUpload([Ljava.lang.String;) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230) ... 67 more /-- Encapsulated exception ------------\ java.lang.NoSuchMethodException: com.xumuye.action.CompanyProductAction.setUpload([Ljava.lang.String;) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315) at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:78) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315) at ognl.ASTProperty.setValueBody(ASTProperty.java:127) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.Ognl.setValue(Ognl.java:737) at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:218) at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:187) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:174) at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:152) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersIntercepto r.java:230) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) \--------------------------------------/
页面上出现的错误:
Struts Problem Report Struts has detected an unhandled exception: Messages: No result defined for action com.xumuye.action.CompanyProductAction and result input Stacktraces No result defined for action com.xumuye.action.CompanyProductAction and result input com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:369) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:271) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) java.lang.Thread.run(Thread.java:619) You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set: struts.devMode=false in your WEB-INF/classes/struts.properties file.
我记得如果你要上传文件upload,你至少需要有uploadFile和uploadFileName字段,你的代码里可能是因为缺少<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;line-height:14.65625px;background-color:#F8F8F8;">uploadFile的原因我居然上传成功了,原因是form那里的提交方式没有修改,我将其改为post就可以了。谢谢你的回答哦。回复<aclass='referer'target='_blank'>@追逐梦想:你的代码里只有upload,并没有uploadFile我的Action中已经有了,谢谢!<divclass="linealt1"><spanstyle="line-height:normal;">struts2上传文件,input的name属性是upload,struts2默认设置的是uploadFile为上传文件,<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;line-height:normal;background-color:#FFFFFF;">uploadFileName为上传文件名。回复<aclass='referer'target='_blank'>@追逐梦想:重新看了一下,form改用post提交。现在是setUpload这个方法中出现了问题了,不知道是什么原因///我以前使用的就是upload这个名字是可以上传的,但是现在不知道怎么了。谢谢!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。