⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentupload.jsp

📁 国外的一套开源CRM
💻 JSP
字号:
<%@ page import="java.util.*, java.net.*" %>

<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%@ page import="javax.servlet.http.HttpServlet" %>

<%@ page import="java.io.IOException" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.File" %>

<%@ page import="http.utils.multipartrequest.ServletMultipartRequest" %>
<%@ page import="http.utils.multipartrequest.MultipartRequest" %>
<%@ page import="com.sourcetap.sfa.replication.*" %>

<%@ include file="/includes/header.jsp" %>

<script>
function updateForm() { }
function closeWin()
{
	window.close();
}
function updateParent()
{
	window.opener.location.href = window.opener.location.href;
}
</script>
<%
	try
	{

		String id = GenericReplicator.getNextSeqId("FileAttachment", delegator);
		response.setContentType("text/html");

		URL sfaPropertiesUrl = application.getResource("/WEB-INF/sfa.properties");

		String filePath = UtilProperties.getPropertyValue(sfaPropertiesUrl, "fileAttachment.path", "files");

		if ( (filePath.indexOf('\\') == - 1) && (filePath.indexOf('/') == -1) )
			filePath = getServletContext().getRealPath("/") + filePath;

		File directory = new File(filePath);
		if ( !directory.isDirectory() )
		{
			boolean created = false;
			try {
				created = directory.mkdir();
			} catch ( Exception e) {}
			if ( !created )
			{
				throw new Exception("Unable to create directory:" + filePath);
			}
		}

		MultipartRequest parser = new ServletMultipartRequest(request, filePath, id);


        GenericValue fileGV = new GenericValue(delegator.getModelEntity("FileAttachment"));
    	fileGV.setDelegator(delegator);

        fileGV.set("fileId", id);
        File saveFile = parser.getFile("file");
        if ( saveFile == null )
			throw new Exception("No file specified");

//		out.write( "file = " + saveFile.getCanonicalPath() );
        fileGV.set("fileLocation", saveFile.getCanonicalPath() );

        String fileName = saveFile.getName();
        fileName = fileName.substring(id.length());
		fileGV.set("fileName", fileName);
//		out.write("fileName = " + fileName);

		Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
        fileGV.set("createdBy", userInfo.getPartyId());
        fileGV.set("createdDate", now);
        fileGV.set("modifiedBy", userInfo.getPartyId());
        fileGV.set("modifiedDate", now);

        String description = parser.getURLParameter("description");
        if ( description != null )
			fileGV.set("description", description);

		List storeGVL = new LinkedList();
		storeGVL.add(fileGV);

		String linkParams[] = { "accountId", "contactId", "productId", "dealId", "activityId", "leadId" };
		String linkEntities[] = { "AccountFile", "ContactFile", "ProductFile", "DealFile", "ActivityFile", "LeadFile" };

		int numLinks = 0;
		for ( int i = 0; i < linkParams.length; i ++ )
		{
			String linkValue = parser.getURLParameter(linkParams[i]);
			if ( linkValue != null )
			{
				GenericValue linkGV = new GenericValue(delegator.getModelEntity(linkEntities[i]));
				linkGV.setDelegator(delegator);
				linkGV.set(linkParams[i], linkValue);
				linkGV.set("fileId", id );
				linkGV.set("createdBy", userInfo.getPartyId());
				linkGV.set("createdDate", now);
				linkGV.set("modifiedBy", userInfo.getPartyId());
				linkGV.set("modifiedDate", now);

				storeGVL.add(linkGV);
				numLinks++;
			}
		}
		if ( numLinks < 1 )
			throw new Exception("File must be attached to an Account, Contact, Product, Opportunity, Activity, or Lead");


        delegator.storeAll(storeGVL);
		out.write("File Uploaded!");
%>
	<BODY onunload=updateParent()>
	<CENTER>
	File Loaded.  Press OK to continue
	<form action="">
		<input type=button onclick=closeWin() value="OK">
	</form>
	</CENTER>
<%
/*
		window.opener.location.href = window.opener.location.href;


		out.println(parser.getHtmlTable());

		out.write("<P><a href=/sfa/control/attachmentDownload?fileId=" + id + ">click here</a> to download the file");
*/
	}
	catch (Exception e)
	{
		try{
			InputStream in = request.getInputStream();
			while ( in.read() !=-1);
		}catch(Exception e2)
		{
		}
		e.printStackTrace();
		out.write("<P><I>" + e.toString());
	}
%>

<%@ include file="/includes/footer.jsp" %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -