引用:
原帖由 xwzsky 于 2008-8-14 11:24 发表 
OA用户提交时,新闻Q同时发送到服务器A和服务器B这个办法已实现一半了——即文字能同时实现同步显示,图片则不能……因为我OA服务器上的SQL数据库记录图片的路径为“images”,但在“images”文件夹里找不到这些上传 ...
我想在上传代码文加多一条网站服务器上传路径,这样可行不?或还要怎样改动呢? 代码如下:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.io.*,java.sql.*,dep.upload.*"%>
<%@ page import = "dep.beans.*" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="mySmartUpload" scope="page" class="dep.upload.SmartUpload" />
<%
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
Connection conn = null;
Statement stmt = null;
String processInsId ="";
processInsId = mySmartUpload.getRequest().getParameter("processInsId");
if(processInsId==null){
out.print("<script language='javascript'>");
out.print("alert('没有实例ID,不能上传正文!');");
out.print("</script>");
return;
}
System.out.println("uploaddoc.jsp Request processInsId:"+processInsId );
//取消注释以保存文件
//mySmartUpload.save("/jspdemo/upload");
try
{
conn = Conn.getConn();
if (conn == null) {
out.print("<script language='javascript'>");
out.print("alert('连接数据库失败!');");
out.print("</script>");
return;
}
}
catch(Exception e)
{
System.err.println("DBconn (): " + e.getMessage());
}
dep.upload.SmartFile myFile = null;
dep.upload.SmartFile file= mySmartUpload.getFiles().getFile(0);
if(file.getSize()<=0){
System.out.println("没有要上传的正文!");
out.print("<script language='javascript'>");
out.print("alert('没有要上传的正文!');");
out.print("</script>");
return;
}
System.out.println("文件大小:"+file.getSize());
//debug only
//处理数据及文件
String UserID="";
String processStartorNo=session.getAttribute("UserNo").toString();
// 根据用户名,取得所在公司,部门 begin
dep.beans.UserInfo jb = new dep.beans.UserInfo();
ArrayList re = new ArrayList();
re = jb.getUserInfo(processStartorNo);
if (((String) re.get(0)).equals("0")) {
ArrayList ra = (ArrayList) re.get(1);
Map rm = (Map) ra.get(0);
UserID = rm.get("id").toString();
}
// 根据用户名,取得所在公司,部门 end;
String path=getServletContext().getRealPath("/")+"oa/FileTemp/"+UserID;
String path="219.22.**.**(网站的IP地址)"+"oa/FileTemp/"+UserID;
File ff= new File(path);
if (!ff.exists()) {
ff.mkdirs();
}
path+="/temp.doc";
file.saveAs(path,mySmartUpload.SAVE_PHYSICAL);
java.io.File tfile = new java.io.File(path);
java.io.InputStream inStream=new java.io.FileInputStream(tfile);
try
{
String strSql="update I_FC_xinxishepi set doc=? where processInsId="+processInsId;
PreparedStatement ps = conn.prepareStatement(strSql);
ps.setBinaryStream(1,inStream,inStream.available());
int count=ps.executeUpdate();
System.out.println("update count:"+count);
ps.close();
conn.close();
}
catch(Exception ex)
{
ex.printStackTrace();
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
inStream.close();
//tfile.delete();
%>
[
本帖最后由 xwzsky 于 2008-8-14 18:00 编辑 ]