package oss.rms.app.analysis.query.business.impl;
import java.io.File;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import oss.rms.app.qrcode.business.IQrCodeBo;
import oss.rms.general.Attachment_File;
import oss.rms.inventory.instance.node.business.ICableConnectorBo;
import oss.rms.inventory.instance.node.business.IDeviceBo;
import oss.rms.inventory.instance.node.business.IOcableConnectorBo;
import oss.rms.inventory.instance.node.domain.CableConnector;
import oss.rms.inventory.instance.node.domain.Device;
import oss.rms.inventory.instance.node.domain.OcableConnector;
import oss.rms.inventory.number.nbr.service.impl.JSONUtil;
import oss.service.security.util.ServerSecuData;
import oss.util.service.IService;
import oss.util.service.SDO;
import oss.util.spring.SpringContextFactory;
import oss.util.variable.VariableHelper;
public class DeviceCheckAction extends DispatchAction{
private WebApplicationContext getWAC(HttpServletRequest request){
WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
return wac;
}
//初始化下拉列表
private void init(HttpServletRequest request){}
public void uploadPicture(ActionMapping mapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response)throws NumberFormatException, Exception {
System.out.println("进入设备图片上传");
String message = "图片上传成功!";
String deviceId ="";
String staffId = "";
String areaId = "";
String localNetId ="";
request.setCharacterEncoding("UTF-8");
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
System.out.println("表单参数名:" + item.getFieldName() + ",表单参数值:" + item.getString("UTF-8"));
if ("deviceId".equals(item.getFieldName())) {
deviceId = new String(item.getString("UTF-8"));
}else if ("staffId".equals(item.getFieldName())) {
staffId = new String(item.getString("UTF-8"));
}else if ("areaId".equals(item.getFieldName())) {
areaId = new String(item.getString("UTF-8"));
}else if ("localNetId".equals(item.getFieldName())) {
localNetId = new String(item.getString("UTF-8"));
}
} else {
if (item.getName() != null && !item.getName().equals("")) {
System.out.println("上传文件的大小:" + item.getSize());
System.out.println("上传文件的类型:" + item.getContentType());
System.out.println("上传文件的名称:" + item.getName());
Long fileSize =item.getSize();
File imgFile = new File(item.getName());
String fileName =imgFile.getName();
File file = new File("/home/weblogic/"+fileName);
item.write(file);
message="上传文件成功!";
}else{
message="没有选择上传文件!";
}
}
}
}catch(FileUploadException e){
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message", "上传文件失败!");
}
response.setContentType("text/html;charset=utf-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");
Writer out = response.getWriter();
out.write(message);
System.out.println("图片上传完成!");
out.flush();
out.close();
}
}
评论3
最新资源