📄 uploadactiveaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.oa.companyculture.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.oa.db.Active;
import com.oa.db.ActiveDAO;
import com.oa.uploadfile.SmartFile;
import com.oa.uploadfile.SmartUpload;
import com.oa.uploadfile.SmartUploadException;
/**
* MyEclipse Struts
* Creation date: 09-24-2007
*
* XDoclet definition:
* @struts.action validate="true"
* @struts.action-forward name="success" path="/company/addactive.jsp"
*/
public class UploadactiveAction extends Action {
/*
* Generated Methods
*/
ActiveDAO adao;
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
response.setCharacterEncoding("gbk");
HttpSession session = request.getSession();
String realname = (String)session.getAttribute("realname");
String username=(String)session.getAttribute("username");
PrintWriter out=null;
try {
out = response.getWriter();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
if(username!=null){
SimpleDateFormat format1=new SimpleDateFormat("yyyyMMddHHmmss");
SmartUpload su = new SmartUpload();// 新建一个SmartUpload对象
try {
//上传初始化 System.out.println(judgingtime);
// 设定上传限制
//su.setMaxFileSize(10000);// 1.限制每个上传文件的最大长度。
// su.setAllowedFilesList("jpg");// 2.设定允许上传的文件(通过扩展名限制)。
su.initialize(request.getSession().getServletContext(),request,response);
su.upload();
} catch (Exception e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 将上传文件保存到指定目录
String filename="";
String realfilename="";
String strfile = "";
String realstrfile = "";
String filename2="";
for(int i=0;i<su.getFiles().getCount();i++){
SmartFile f=su.getFiles().getFile(i);
realfilename = f.getFileName();
filename=format.format(new java.util.Date());
// String b = "."+f.getFileExt();
// String a = "["+filename+"]"+"."+f.getFileExt();
// filename2=realfilename.replace(b, a);
filename2=f.getFileName();
if(i==0){
strfile=filename;
realstrfile=realfilename;
}else{
strfile=strfile+"///"+filename;
realstrfile=realstrfile+"///"+realfilename;
}
String strPath="d:/oafile/oaactive/"+filename2;
try {
f.saveAs(strPath,SmartUpload.SAVE_PHYSICAL);
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
String topic = su.getRequest().getParameter("topic");
String[] discribe = su.getRequest().getParameterValues("discribe");System.out.println(discribe.length);
String a = discribe[0];
for(int i=1;i<discribe.length;i++){
a = a +"///"+discribe[i];
}
Active co = new Active();
co.setTopic(topic);
co.setPicture(strfile);
co.setRealpicture(realstrfile);
co.setDiscribe(a);
co.setRealname(realname);
Date savedate = new Date();
co.setSavedate(savedate);
adao.save(co);
out.print("<script>");
out.print("alert('上传成功!');");
out.print("document.location.href = 'company/addactive.jsp'");
out.print("</script>");
out.flush();
}else{
out.print("<script>alert('您的操作超时,请重新登录!');");
out.print("window.open('login.jsp','_top');");
out.print("</script>");
out.flush();
}
return null;
}
public ActiveDAO getAdao() {
return adao;
}
public void setAdao(ActiveDAO adao) {
this.adao = adao;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -