先上传到自己设定的目录,然后在服务器上用BEAN把它存进数据库,我的是SQLSERVER,你看看道理应该是一样的
解决方案 »
- java相关,关于Dtree的问题!在线等!
- jsp的request里有一货币对象的list,我想保存在js的数组里
- javabean+jsp的分页
- java/JSP中文乱码问题?
- response.sendRedirect()与window.location.href的不同
- jboss 问题,急,各位大侠帮忙啊
- myeclipse导入jsp项目后出现如下错误..........
- 菜鸟的问题:要怎么样在本窗口打开一个新页面,但这个页面回退不到前面这个页面?
- 我现在要做一个聊天室,不过我以前没有做过,没有思路.(JSP+BEAN)
- 看看这个oracle触发器哪里写错了!
- javax.sql包在什么地方能找到?
- 新手问些问题
{
conn=dbc.getConnection();
String relPath= System.getProperty("user.dir").toString();
String filePathAll=relPath.substring(0,relPath.length()-3)+"server/default/deploy/dzzw.ear/dzzw.war/singINPicture/"+userID+".jpg";
//System.out.print(filePathAll);
try{
java.io.File file = new java.io.File(filePathAll);
java.io.FileInputStream fis = new java.io.FileInputStream(file);
PreparedStatement pstmt = conn.prepareStatement("update gg_ryxxb_m set imgUnderWrite= ? where userID=?");
pstmt.setBinaryStream(1, fis,fis.available());
pstmt.setString(2, userID);
pstmt.execute();
fis.close();
System.out.print("enter"+userID);
}catch(Exception err)
{
System.out.print(err.getMessage());
return -2;
} return 0;
}
<%@page contentType="text/html;charset=gb2312"%>
<%@ page language="java"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<jsp:useBean id="userData" scope="page" class="cn.com.huiyuanit.xtgl.userDataOperation"/>
<% String userID=request.getParameter("userID");
ResultSet rs1 = userData.queryImgUnderWrite(userID);
try{
int i=0;
if(rs1.next())
{
InputStream in=rs1.getBinaryStream("imgUnderWrite");
response.reset();
response.setContentType("image/jpeg");
byte[] b = new byte[1024];
int len;
while((len=in.read(b,0,b.length))>0)
response.getOutputStream().write(b,0,len);
in.close();
}
else
{
out.print("no image");
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
rs1.close();
userData.dbClose();
}
%>
</body>
</html>
有很多文章
想当时做clob也是忙的半死:)
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
<script>
function MediaSubmit(TypeValue,Id)
{
MediaForm.TypeValue.value=TypeValue;
MediaForm.RecordId.value=Id;
MediaForm.submit();
}
function ShowMedia(Id,Type)
{
var hwnd=window.open('','','');
switch(Type)
{
case "image/*":
hwnd.document.write("<Img src='/System/Media/Show.jsp?Id="+Id+"&Type="+Type+"' border=0></a>");
break;
case "audio/*":
hwnd.document.write("<BgSound src='/System/Media/Show.jsp?Id="+Id+"&Type="+Type+"' border=0>");
break;
case "video/*":
hwnd.document.write("<Img dynsrc='/System/Media/Show.jsp?Id="+Id+"&Type="+Type+"' border=0></a>");
break;
case "application/msword":
hwnd.location.href="/System/Media/Show.jsp?Id="+Id+"&Type="+Type;
break;
case "application/vnd.ms-excel":
hwnd.location.href="/System/Media/Show.jsp?Id="+Id+"&Type="+Type;
break;
case "application/*":
hwnd.location.href="/System/Media/Show.jsp?Id="+Id+"&Type="+Type;
break;
default:
break;
}
}
</script>
</head><body>
<%@ include file="/TemplateLib/Head.jsp"%>
<center>
<form action="Result.jsp" method="post" name="MediaForm" enctype="multipart/form-data">
<input type="hidden" name="TypeValue" size="10" value="">
<input type="hidden" name="RecordId" size="10" value="">
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="10%" class="TdClass_Head">多媒体库</td>
</tr>
</table>
<br>
<table border="0" width="80%" cellspacing="0" cellpadding="0">
<tr>
<td width="10%" class="TdClass_0">媒体描述</td>
<td width="30%" class="TdClass_0">媒体分类</td>
<td width="10%" class="TdClass_0">媒体类型</td>
<td width="40%" class="TdClass_0">媒体文件</td>
<td width="10%" class="TdClass_0">执行操作</td>
</tr>
<tr>
<td width="10%" class="TdClass_1"><input name="Re" size="10" value=""></td>
<td width="30%" class="TdClass_1">
<select name="Category" size=1 style="width:80%">
<option value="">--请选择--</option>
<%
odbcQuery="select distinct Category from MediaLib";
odbcRs=odbcStmt.executeQuery(odbcQuery);
String Category;
while(odbcRs.next())
{
Category=odbcRs.getString("Category");
%>
<option value="<%=Category%>"><%=Category%></option>
<%
}
odbcRs.close();
%>
</select>
<script>
function AddCategory()
{
var m_Category="";
m_Category=window.prompt("请输入媒体分类","");
if(m_Category!="")
{
MediaForm.Category.length=MediaForm.Category.length+1;
MediaForm.Category.options[MediaForm.Category.length-1].text=m_Category;
MediaForm.Category.options[MediaForm.Category.length-1].value=m_Category;
MediaForm.Category.options[MediaForm.Category.length-1].selected="selected";
}
}
</script>
<input type="button" value="." id="" name="" onclick="AddCategory()">
</td>
<td width="20%" class="TdClass_1">
<select name="Type" size=1 style="width:80%">
<option value="">--请选择--</option>
<option value="image/*">图像</option>
<option value="audio/*">音频</option>
<option value="video/*">视频</option>
<option value="application/msword">文档</option>
<option value="application/vnd.ms-excel">表格</option>
<option value="application/*">应用</option>
</select>
</td>
<td width="30%" class="TdClass_1"><input type="file" name="MediaFile" size="10" value=""><a href="#">浏览媒体</a></td>
<td width="10%" class="TdClass_1"><input type="button" onclick="MediaSubmit('Add','NULL')" value="增加" id=Add name=Add></td>
</tr>
<%
odbcQuery="select * from MediaLib";
odbcRs_=odbcStmt.executeQuery(odbcQuery);
String Id,Type;
int iCount;
iCount=0;
while(odbcRs_.next())
{
Id=odbcRs_.getString("ID");
Type=odbcRs_.getString("Type");
if(iCount%2==0)
{
%>
<tr>
<td width="10%" class="TdClass_0"><input name="Re<%=Id%>" size="10" value="<%=odbcRs_.getString("Re")%>"></td>
<td width="30%" class="TdClass_0"><input name="Category<%=Id%>" size="10" value="<%=odbcRs_.getString("Category")%>" readonly></td>
<td width="10%" class="TdClass_0"><input name="Type<%=Id%>" size="10" value="<%=Type%>" readonly></td>
<td width="40%" class="TdClass_0"><input type="file" name="MediaFile<%=Id%>" size="10" value=""><a href="#" onclick="ShowMedia('<%=Id%>','<%=Type%>')">浏览媒体</a></td>
<td width="10%" class="TdClass_0"><input type="button" onclick="MediaSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="MediaSubmit('Del','<%=Id%>')" value="删除" id=Del name=Del></td>
</tr>
<% }else{%>
<tr>
<td width="10%" class="TdClass_1"><input name="Re<%=Id%>" size="10" value="<%=odbcRs_.getString("Re")%>"></td>
<td width="30%" class="TdClass_1"><input name="Category<%=Id%>" size="10" value="<%=odbcRs_.getString("Category")%>" readonly></td>
<td width="10%" class="TdClass_1"><input name="Type<%=Id%>" size="10" value="<%=Type%>" readonly></td>
<td width="40%" class="TdClass_1"><input type="file" name="MediaFile<%=Id%>" size="10" value=""><a href="#" onclick="ShowMedia('<%=Id%>','<%=Type%>')">浏览媒体</a></td>
<td width="10%" class="TdClass_1"><input type="button" onclick="MediaSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="MediaSubmit('Del','<%=Id%>')" value="删除" id=Del name=Del></td>
</tr>
<%
}
iCount++;
}
odbcRs_.close();
%>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" class="TdClass_Head"><input type="button" value="返回" id="Return" name="Return" onclick="window.location.href='/System/Index.jsp'"></td>
</tr>
</table>
</form>
</center>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
InputStream InData=null;
int iSize,iLength;
iLength=request.getContentLength();
byte[] Buffer=new byte[iLength];
byte[] Byte_File;
if(iLength>0)
{
InData=request.getInputStream();
String ContentType=request.getContentType();
iSize=InData.read(Buffer);
if(iSize!=-1)
{
//数据处理开始
String FileData=new String(Buffer);
//正则字串:"name=\"";
//正则字串:"filename=\"";
String strSplit=ContentType.substring(ContentType.lastIndexOf("=")+1,ContentType.length());
String strSub[]=FileData.split(strSplit); String strElement;
int iBegin,iEnd;
iBegin=0;iEnd=0;
String FieldName,FieldValue;
int bTrue;
bTrue=0;
int iPos;
iPos=0;
int iLocation;
iLocation=0;
for(int iIndex=0;iIndex<strSub.length;iIndex++)
{
strElement=strSub[iIndex];
iBegin=strElement.indexOf("name=\"",0);
if(iBegin!=-1)
{
iEnd=strElement.indexOf("\"",iBegin+6);
FieldName=strElement.substring(iBegin+6,iEnd);
iBegin=strElement.indexOf("filename=\"",0);
if(iBegin!=-1)
{
bTrue=1;
}
//
iEnd=strElement.indexOf("\r\n\r\n",0);
if(bTrue==1)
{
iLocation=0;
iPos=FileData.indexOf("filename=\"",iPos);
iPos=FileData.indexOf("\n",iPos)+1;
iPos=FileData.indexOf("\n",iPos)+1;
iPos=FileData.indexOf("\n",iPos)+1;
iLocation=FileData.indexOf(strSplit,iPos)-4;
FieldValue=FileData.substring(iPos,iLocation);
byte[] Byte_File_=FieldValue.getBytes();
Byte_File=new byte[Byte_File_.length];
for(int kIndex=0;kIndex<Byte_File_.length;kIndex++)
{
Byte_File[kIndex]=Buffer[iPos+0+kIndex];
//0:Excel
//0:Word
//
}
session.putValue(FieldName,Byte_File);
}
else
{
FieldValue=strElement.substring(iEnd+4);
session.putValue(FieldName,FieldValue.substring(0,FieldValue.indexOf("\n")-1));
}
bTrue=0;
}
}
//数据处理结束
String TypeValue,Id;
TypeValue=(String)session.getValue("TypeValue");
if(TypeValue!=null)
{
int iDoAction;
iDoAction=0;
if(TypeValue.indexOf("Add",0)!=-1)
{iDoAction=1;}
if(TypeValue.indexOf("Modify")!=-1)
{iDoAction=2;}
if(TypeValue.indexOf("Del")!=-1)
{iDoAction=3;}
odbcQuery="";
Id=(String)session.getValue("RecordId");
boolean bDefault;
int iC;
oracle.sql.BLOB m_Blob;
switch(iDoAction)
{
case 1:
bDefault=odbcConn.getAutoCommit();
odbcConn.setAutoCommit(false);
odbcStmt.executeUpdate("insert into MediaLib(ID,Category,Type,MediaFile,Re) values(IDSERIAL.nextval,'"+(String)session.getValue("Category")+"','"+(String)session.getValue("Type")+"',EMPTY_BLOB(),'"+(String)session.getValue("Re")+"')");
odbcQuery="select * from MediaLib order by ID asc";
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
String iID=String.valueOf((int)odbcRs.getInt("ID"));
odbcQuery="select MediaFile from MediaLib where ID="+iID+" for Update";
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
m_Blob=(oracle.sql.BLOB)odbcRs.getBlob("MediaFile");
BufferedOutputStream pOutAdd=new BufferedOutputStream(m_Blob.getBinaryOutputStream());
ByteArrayInputStream pInAdd=new ByteArrayInputStream((byte[])session.getValue("MediaFile"));
while((iC=pInAdd.read())!=-1)
{pOutAdd.write(iC);}
pInAdd.close();
pOutAdd.close();
odbcConn.commit();
odbcConn.setAutoCommit(bDefault);
response.sendRedirect("/System/Media/List.jsp");
break;
case 2:
bDefault=odbcConn.getAutoCommit();
odbcConn.setAutoCommit(false);
odbcStmt.executeUpdate("update MediaLib set MediaFile=EMPTY_BLOB() where ID="+Id);
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
m_Blob=(oracle.sql.BLOB)odbcRs.getBlob("MediaFile");
BufferedOutputStream pOutModify=new BufferedOutputStream(m_Blob.getBinaryOutputStream());
ByteArrayInputStream pInModify=new ByteArrayInputStream((byte[])session.getValue("MediaFile"));
while((iC=pInModify.read())!=-1)
{pOutModify.write(iC);}
pInModify.close();
pOutModify.close();
odbcConn.commit();
odbcConn.setAutoCommit(bDefault);
response.sendRedirect("/System/Media/List.jsp");
break;
case 3:
odbcStmt.executeUpdate("delete from MediaLib where ID="+Id);
response.sendRedirect("/System/Media/List.jsp");
break;
}
}
}
}
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
</head><body onload="window.alert('动作失败,系统取消操作!');window.location.href='/System/Media/List.jsp';">
<%@ include file="/TemplateLib/Head.jsp"%>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
</head><body>
<%@ include file="/TemplateLib/Head.jsp"%>
<br>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="10%" class="TdClass_Head">多媒体库</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<%
odbcQuery="select distinct Category from MediaLib";
odbcRs=odbcStmt.executeQuery(odbcQuery);
String Category;
int iCount;
iCount=0;
while(odbcRs.next())
{
iCount++;
Category=odbcRs.getString("Category");
%>
<td width="20%" class="TdClass_1">
<a href="Browse.jsp?Category=<%=Category%>" style="color: #800000; font-size: 9pt; font-family: 宋体"><%=Category%></a>
</td>
<%if(iCount%5==0){%></tr><tr><%}%>
<%
}
odbcRs.close();
%>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<%
int Page;
String strPage;
strPage=request.getParameter("Page");
if(strPage==null)
{
Page=1;
}
else
{
Page=java.lang.Integer.parseInt(strPage);
}
Category=request.getParameter("Category");
if(Category!=null)
{
odbcQuery="select * from MediaLib where Category='"+Category+"'";
}
else
{
odbcQuery="select * from MediaLib";
}
odbcRs_=odbcStmt_.executeQuery(odbcQuery);
int RecordSum,PageSum,PageSize;
RecordSum=0;
PageSum=0;
odbcRs_.last();
RecordSum=odbcRs_.getRow();
PageSize=10;
PageSum=(RecordSum+PageSize-1)/PageSize;
if(Page>PageSum){Page=PageSum;}
if(PageSum>0)
{
odbcRs_.absolute((Page-1)*PageSize+1);
iCount=0;
String Id,Type,Re;
while(iCount<PageSize&&!odbcRs_.isAfterLast())
{
iCount++;
Id=odbcRs_.getString("ID");
Type=odbcRs_.getString("Type");
Re=odbcRs_.getString("Re");
%>
<td width="20%" class="TdClass_1">
<%if(Type.equals("image/*")){%>
<br><img src="/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>" width=80 height=80 title="<%=Re%>"><br>
<%}else if(Type.equals("audio/*")){%>
<br><a href="#" onclick="var hwnd=window.open('','','');hwnd.document.write('<BgSound src=\'/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>\'>');"><%=Re%></a><br>
<%}else if(Type.equals("video/*")){%>
<br><img dynsrc="/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>" width=80 height=80 title="<%=Re%>"><br>
<%}else if(Type.equals("application/msword")){%>
<br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
<%}else if(Type.equals("application/vnd.ms-excel")){%>
<br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
<%}else if(Type.equals("application/*")){%>
<br><a href="#" onclick="window.open('/System/Media/Show.jsp?Id=<%=Id%>&Type=<%=Type%>','','')"><%=Re%></a><br>
<%}else{%>
<br><br>
<%}%>
</td>
<%if(iCount%5==0){%></tr><tr><%}%>
<%
odbcRs_.next();
}
}
odbcRs_.close();
for(int iResult=0;iResult<5-iCount%5+1;iResult++)
{
%>
<td width="20%" class="TdClass_1"><br><br></td>
<%
}
%>
</tr>
</table>
<table border="0" width="80%" class="SubPageClass">
<tr>
<td width="25%" class="TdClass_0"><%if(Page>1){%><a href="Browse.jsp?Category=<%=Category%>&Page=<%=Page-1%>">上一页</a><%}%></td>
<td width="25%" class="TdClass_0">记录<%=RecordSum%>条</td>
<td width="25%" class="TdClass_0">共有<%=PageSum%>页</td>
<td width="25%" class="TdClass_0"><%if(Page<PageSum){%><a href="Browse.jsp?Category=<%=Category%>&Page=<%=Page+1%>">下一页</a><%}%></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" class="TdClass_Head"><input type="button" value="返回" id="Return" name="Return" onclick="window.location.href='/Index.jsp'"></td>
</tr>
</table>
</form>
</center>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
输出
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
String Id,TypeValue;
Id=request.getParameter("Id");
TypeValue=request.getParameter("Type");
odbcQuery="select * from MediaLib where ID="+Id;
odbcRs=odbcStmt.executeQuery(odbcQuery); byte[] Buffer=new byte[1024*10];
InputStream InData=null;
OutputStream outData=null;
int iSize;
if(odbcRs.next())
{
outData=response.getOutputStream();
InData=odbcRs.getBinaryStream("MediaFile");
response.setContentType(TypeValue);
while(true)
{
iSize=InData.read(Buffer);
if(iSize==-1)
{
break;
}
outData.write(Buffer,0,iSize);
}
outData.flush();
response.flushBuffer();
}
odbcRs.close();
%>
<%@ include file="/DataIni/DataClose.jsp"%>