问题描述
SQLServer2005createdatabaseBigObjectgouseBigObjectgocreatetableusers(idintidentityprimarykey,namevarchar(10)notnull,photoimagenotnull)只用Struts2框架实体Beanpackagecom.db;importjava.io.File;publicclassUser{privateintid;privateStringname;privateFilephoto;publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicFilegetPhoto(){returnphoto;}publicvoidsetPhoto(Filephoto){this.photo=photo;}}逻辑方法packagecom.biz;importjava.util.ArrayList;importjava.util.List;importcom.db.User;importcom.biz.*;publicclassUserAction{privateList<User>users=newArrayList<User>();publicList<User>getUsers(){returnusers;}publicvoidsetUsers(List<User>users){this.users=users;}publicStringsave(){UserImplui=newUserImpl();//插入数据库if(ui.savePhoto(users)){return"s";}else{return"e";}}}插入数据库逻辑方法packagecom.biz;importcom.db.*;importjava.io.File;importjava.io.FileInputStream;importjava.sql.*;importjava.util.List;importsun.jdbc.odbc.JdbcOdbcDriver;publicclassUserImpl{publicbooleansavePhoto(List<User>users){try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connectioncnn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DataBaseName=BigObject","sa","sa");for(inti=0;i<users.size();++i){Useruser=users.get(i);PreparedStatementpstmt=cnn.prepareStatement("insertusersvalues(?,?)");pstmt.setString(1,user.getName());Filephoto=user.getPhoto();FileInputStreamin=newFileInputStream(photo);pstmt.setBinaryStream(2,in,in.available());pstmt.execute();}returntrue;}catch(Exceptionex){System.out.println(ex.getMessage());}returnfalse;}}JSP页面<%@pagecontentType="text/html;charset=gbk"%><html><head></head><body><formaction="/upLoad/userAction"method="post"enctype="multipart/form-data"><inputtype="text"name="users.user.name"><br><inputtype="file"name="users.user.photo"><br><inputtype="text"name="users.user.name"><br><inputtype="file"name="users.user.photo"><br><inputtype="submit"value="提交"></form></body></html>exampl.xml文件<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><packagename="example"namespace="/"extends="struts-default"><actionname="userAction"class="com.biz.UserAction"method="save"><resultname="s">/success.jsp</result><resultname="e">/index.jsp</result></action></package></struts>报错2009-8-319:59:56com.opensymphony.xwork2.util.logging.commons.CommonsLoggerinfo信息:Unabletofind'struts.multipart.saveDir'propertysetting.Defaultingtojavax.servlet.context.tempdir2009-8-319:59:57com.opensymphony.xwork2.util.logging.commons.CommonsLoggerwarn警告:Errorsettingvalueognl.NoSuchPropertyException:java.util.ArrayList.useratognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:122)atognl.ListPropertyAccessor.getProperty(ListPropertyAccessor.java:60)atcom.opensymphony.xwork2.ognl.accessor.XWorkListPropertyAccessor.getProperty(XWorkListPropertyAccessor.java:71)atognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)atognl.ASTProperty.getValueBody(ASTProperty.java:92)atognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)atognl.SimpleNode.getValue(SimpleNode.java:210)atognl.ASTChain.setValueBody(ASTChain.java:168)atognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)atognl.SimpleNode.setValue(SimpleNode.java:246)atognl.Ognl.setValue(Ognl.java:476)atcom.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)atcom.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:155)atcom.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:143)atcom.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters