jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
<%@ taglib prefix="d" tagdir="/WEB-INF/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager"%>
<%
String path = request.getContextPath();
request.setAttribute("rootPath",path);
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD id=Head1><TITLE>检验报告维护</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK
href="<%=path %>/css/style.css" type=text/css rel=stylesheet><LINK
href="<%=path %>/css/manage.css" type=text/css rel=stylesheet>
<SCRIPT language=javascript src="<%=path %>/js/FrameDiv.js"></SCRIPT>
<SCRIPT language=javascript src="<%=path %>/js/Common.js"></SCRIPT>
<SCRIPT language=javascript src="<%=path %>/js/ajaxupload.js"></SCRIPT>
<script type="text/javascript" src="<%=path %>/manager/js/encManager.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<%=path %>/js/ajaxupload.js"></script>
<script type="text/javascript">
//ajax文件上传
$(document).ready(function(){
$("input:[name=jreportName]").each(function(){
new AjaxUpload(this, {
action: '<%=path%>/manager/toUploadReportFile.do?',
name: 'uploadFile',
onSubmit : function(file, ext){
var bid= this._button.id;
var bianhao=bid.split("jreportName_")[1];
var batchTxts =document.getElementById("batchTxt_"+bianhao).innerHTML ;
var commodityIds=document.getElementById("commodityId").value
var validityDates=document.getElementById("validityDate_"+bianhao).innerHTML;
this.setData({
'batchTxt':batchTxts,
'commodityId': commodityIds,
'validityDate':validityDates
});
this.disable();
},
onComplete: function(file, response){
if(response=='fail'){
alert('上传文件大小超过限制60M 出错!');
this.enable();
return;
}
this.enable();
var bid= this._button.id;
var bianhao=bid.split("jreportName_")[1];
document.getElementById("number_"+bianhao).innerHTML=file;
document.getElementById("realTestUrl_"+bianhao).innerHTML=file;
document.getElementById("number_"+bianhao).href="javascript:showTestReportContent('"+response+"','realTestUrl_"+bianhao+"')";
}
});
});
});
</script>
</HEAD>
<BODY>
<s:iterator id="reportlst" value="#request.testReportListDefend.data">
<TD>
<TABLE id=grid
style="BORDER-TOP-WIDTH: 0px; FONT-WEIGHT: normal; BORDER-LEFT-WIDTH: 0px; BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-WIDTH: 0px; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; FONT-STYLE: normal; BACKGROUND-COLOR: #cccccc; BORDER-RIGHT-WIDTH: 0px; TEXT-DECORATION: none; BORDER-RIGHT-COLOR: #cccccc"
cellSpacing=1 cellPadding=2 rules=all border=0>
<TBODY>
<TR class="trbiaotou">
<TD>批号</TD>
<TD>有效期</TD>
<TD>检验报告</TD>
<TD>更新检验报告</TD>
</TR>
<s:iterator id="repNumDelst" value="#request.reportNumDefendlst.data" status="st">
<TR οnmοuseοver="this.style.background='lightsteelblue'" οnmοuseοut="this.style.background='#FFFFFF'"
class="trinfo">
<TD><span id="batchTxt_<s:property value="#st.getIndex()+1"/>"><s:property value="#request.repNumDelst.batchTxt"/></span> </TD>
<TD align='center'> <span id="validityDate_<s:property value="#st.getIndex()+1"/>"><s:property value="#request.repNumDelst.validityDate"/></span></TD>
<TD>
<a id="number_<s:property value="#st.getIndex()+1"/>" href="javascript:showTestReportContent('<s:property value="#request.repNumDelst.testUrl"/>','realTestUrl_<s:property value="#st.getIndex()+1"/>');"> <s:property value="#request.repNumDelst.realTestUrl"/> </a> </TD>
<td align='center'><input type="button" name="jreportName" id="jreportName_<s:property value="#st.getIndex()+1"/>" value="更新检验报告" /></td>
<td style="display:none"> <span id="realTestUrl_<s:property value="#st.getIndex()+1"/>"><s:property value="#request.repNumDelst.realTestUrl"/></span></td>
</TR>
</s:iterator>
</TBODY></TABLE>
</FORM></BODY></HTML>
Action:
//上传检验报告
private static final int BUFFER_SIZE = 1024;
private File uploadFile;
private String uploadFileFileName;
private String uploadFileContentType;
/**
* 文件上传
// 更新检验报告
* @return
*/
@Action(value = "toUploadReportFile", results = {
@Result(name = "fail", type = "dispatcher", location = "/login.jsp"),
@Result(name = "success", type = "dispatcher", location = "/manager/surveyReportDefend.jsp"),
@Result(name = "input", type = "dispatcher", location = "/manager/error.jsp") }
)
public String toUploadReportFile() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html; charset=utf-8");
if(null!=uploadFile){
File file = new File(ServletActionContext.getServletContext().getRealPath("/")+"files");
if(!file.exists()){
file.mkdir();
}
String uuId = UUID.randomUUID().toString();
String uploadPath =ServletActionContext.getServletContext().getRealPath("/")+"files"+File.separator+uuId+".t";
File filePath = new File(uploadPath);
FileInputStream inputstream = new FileInputStream(uploadFile);
FileOutputStream os = new FileOutputStream(filePath);
byte[] fileByte = new byte[1024];
while (inputstream.read(fileByte) > 0) {
os.write(fileByte, 0, fileByte.length);
}
TestReport tr= new TestReport();
tr.setTid(UUID.randomUUID().toString());
tr.setBatchTxt(batchTxt);
tr.setCommodityId(commodityId) ;
tr.setTestNumber(this.getUploadFileFileName().substring(0,this.getUploadFileFileName().lastIndexOf("."))) ;
tr.setTestUrl(filePath.getName());
tr.setValidityDate(validityDate);
tr.setRealTestUrl(this.getUploadFileFileName());
testReportservice.updatTestReport(tr);
batchTxt="";
response.getWriter().print(uuId+".t");
}
return null;
}