enctype="multipart/form-data" method="post"
// 这是jsp传递过来的具体文件 xxx,xxxFileName,xxxContentType
private File file;
// 文件名
private String fileFileName;
// 文件类型
private String fileContentType;
@Override
public Clazz getModel() {
return clz;
}
public void copyFile(File from, File to) throws IOException {
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(from));
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(to));
byte[] bbuf = new byte[1024];
int len =0 ;
int num = 0;
while((len = bin.read(bbuf))!=-1) {
bout.write(bbuf, 0, len);
System.out.println(++num+"-------"+len);
}
bout.close();
bin.close();
}
public String upload() {
String dir = "E:/temp/T224";
String serverPath="/upload";
try {
// FileUtils.copyFile(file, new File(dir+"/"+fileFileName));
copyFile(file, new File(dir+"/"+fileFileName));
clz.setPic(serverPath+"/"+fileFileName);
this.clazzDao.edit(clz);
} catch (IOException e) {
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "toList";
}
public String preUpload() {
if (clz.getCid() != 0) {
try {
Clazz c = this.clazzDao.list(clz, new PageBean()).get(0);
request.setAttribute("clz", c);
} catch (InstantiationException | IllegalAccessException | SQLException e) {
e.printStackTrace();
}
}
return "preUpload";
}<package name="sy" extends="base" namespace="/sy">
<interceptors>
<interceptor name="one" class="com.javaxl.crud.web.OneInterceptor"></interceptor>
<interceptor name="two" class="com.javaxl.crud.web.TwoInterceptor"></interceptor>
</interceptors>
<action name="hello_*" class="com.javaxl.web.HelloAction"
method="{1}">
<result name="add">/add.jsp</result>
<result name="edit">/edit.jsp</result>
</action>
<action name="clz_*" class="com.javaxl.crud.web.ClzAction"
method="{1}">
<!-- <interceptor-ref name="one"></interceptor-ref> -->
<!-- <interceptor-ref name="two"></interceptor-ref> -->
<result name="list">/clzList.jsp</result>
<result name="preSave">/clzEdit.jsp</result>
<result name="preUpload">/fileUpload.jsp</result>
<result name="toList" type="redirectAction">clz_list</result>
</action>
</package>
备案号:湘ICP备19000029号
Copyright © 2018-2019 javaxl晓码阁 版权所有