to
www.jspsmart.comtry
using jspsmart.upload("file");
www.jspsmart.comtry
using jspsmart.upload("file");
解决方案 »
- 回答给分,动态创建的input checkbox 该怎么取值,即判断是否选中。
- spring事务提交
- 一个新手关于Hibernate错误的问题!
- JSP高手请进!分不够再加!
- java 多线程问题,急!
- 请问IIS中怎么整合解释jsp的功能?
- 求助:一个jsp中<a href="nw/register.jsp? titleId="<%=rst.getString("titleId")%>"">...</a>的传值问题,如何接收???谢谢各位帮帮
- Help~~~~Help~~~~~Help~~~~~~~(Waiting online...)
- 懒人问题:如何调用SQLSERVER的视图啊
- 运行jeecg框架的demo出错,请问如何更改web.xml
- Random的问题
- 相信大家都有同样问题,用POI如何合并单元格呢,还有画表格线问题。
<%@ 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"%>
<center>
<form action="Result.jsp" method="post" name="LinkForm" enctype="multipart/form-data">
<script>
function LinkSubmit(TypeValue,Id)
{
LinkForm.TypeValue.value=TypeValue;
LinkForm.RecordId.value=Id;
LinkForm.submit();
}
function ShowLogo(SiteName,SiteURL,Id)
{
var hwnd=window.open('','','');
hwnd.document.write("<a href='"+SiteURL+"'><img src='/System/Link/ShowLogo.jsp?Id="+Id+"' title='网站名称:"+SiteName+"' width=80 height=30 border=0></a>");
}
</script>
<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="20%" class="TdClass_0">网站名称</td>
<td width="20%" class="TdClass_0">网站地址</td>
<td width="40%" class="TdClass_0">网站标识</td>
<td width="20%" class="TdClass_0">执行操作</td>
</tr>
<tr>
<td width="20%" class="TdClass_1"><input name="SiteName" size="10" value=""></td>
<td width="20%" class="TdClass_1"><input name="SiteURL" size="10" value=""></td>
<td width="40%" class="TdClass_1"><input type="file" name="SiteLogo" size="10" value=""><a href="#">浏览标识</a></td>
<td width="20%" class="TdClass_1"><input type="button" onclick="LinkSubmit('Add','NULL')" value="增加" id=Add name=Add>
</tr>
<%
odbcQuery="select * from Link";
odbcRs=odbcStmt.executeQuery(odbcQuery);
String Id,SiteName,SiteURL;
int iCount;
iCount=0;
while(odbcRs.next())
{
Id=odbcRs.getString("ID");
SiteName=odbcRs.getString("SiteName");
SiteURL=odbcRs.getString("SiteURL");
if(iCount%2==0)
{
%>
<tr>
<td width="20%" class="TdClass_0"><input name="SiteName<%=Id%>" size="10" value="<%=SiteName%>"></td>
<td width="20%" class="TdClass_0"><input name="SiteURL<%=Id%>" size="10" value="<%=SiteURL%>"></td>
<td width="40%" class="TdClass_0"><input type="file" name="SiteLogo<%=Id%>" size="10" value=""><a href="#" onclick="ShowLogo('<%=SiteName%>','<%=SiteURL%>','<%=Id%>')">浏览标识</a></td>
<td width="20%" class="TdClass_0"><input type="button" onclick="LinkSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="LinkSubmit('Del','<%=Id%>')" value="删除" id=Del name=Del></td>
</tr>
<% }else{%>
<tr>
<td width="10%" class="TdClass_1"><input name="SiteName<%=Id%>" size="10" value="<%=SiteName%>"></td>
<td width="10%" class="TdClass_1"><input name="SiteURL<%=Id%>" size="10" value="<%=SiteURL%>"></td>
<td width="10%" class="TdClass_1"><input type="file" name="SiteLogo<%=Id%>" size="10" value=""><a href="#" onclick="ShowLogo('<%=SiteName%>','<%=SiteURL%>','<%=Id%>')">浏览标识</a></td>
<td width="10%" class="TdClass_1"><input type="button" onclick="LinkSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="LinkSubmit('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>
<%@ 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:Image
}
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 Link(ID,SiteName,SiteURL,SiteLogo) values(IDSERIAL.nextval,'"+(String)session.getValue("SiteName")+"','"+(String)session.getValue("SiteURL")+"',EMPTY_BLOB())");
odbcQuery="select * from Link order by ID asc";
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
String iID=String.valueOf((int)odbcRs.getInt("ID"));
odbcQuery="select SiteLogo from Link where ID="+iID+" for Update";
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
m_Blob=(oracle.sql.BLOB)odbcRs.getBlob("SiteLogo");
BufferedOutputStream pOutAdd=new BufferedOutputStream(m_Blob.getBinaryOutputStream());
ByteArrayInputStream pInAdd=new ByteArrayInputStream((byte[])session.getValue("SiteLogo"));
while((iC=pInAdd.read())!=-1)
{pOutAdd.write(iC);}
pInAdd.close();
pOutAdd.close();
odbcConn.commit();
odbcConn.setAutoCommit(bDefault);
response.sendRedirect("/System/Link/List.jsp");
break;
case 2:
bDefault=odbcConn.getAutoCommit();
odbcConn.setAutoCommit(false);
odbcStmt.executeUpdate("update Link set SiteLogo=EMPTY_BLOB() where ID="+Id);
odbcQuery="select SiteLogo from Link where ID="+Id+" for Update";
odbcRs=odbcStmt___.executeQuery(odbcQuery);
odbcRs.last();
m_Blob=(oracle.sql.BLOB)odbcRs.getBlob("SiteLogo");
BufferedOutputStream pOutModify=new BufferedOutputStream(m_Blob.getBinaryOutputStream());
ByteArrayInputStream pInModify=new ByteArrayInputStream((byte[])session.getValue("SiteLogo"));
while((iC=pInModify.read())!=-1)
{pOutModify.write(iC);}
pInModify.close();
pOutModify.close();
odbcConn.commit();
odbcConn.setAutoCommit(bDefault);
response.sendRedirect("/System/Link/List.jsp");
break;
case 3:
odbcStmt.executeUpdate("delete from Link where ID="+Id);
response.sendRedirect("/System/Link/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/Link/List.jsp';">
<%@ include file="/TemplateLib/Head.jsp"%>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
String Id;
Id=getStr(request.getParameter("Id"));
odbcQuery="select * from Link where ID="+Id;
odbcRs=odbcStmt.executeQuery(odbcQuery); byte[] Buffer=new byte[4096];
InputStream InData=null;
OutputStream outData=null;
int iSize; if(odbcRs.next())
{
outData=response.getOutputStream();
InData=odbcRs.getBinaryStream("SiteLogo");
response.setContentType("image/*");
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"%>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<body>
<% String str=response.encodeURL("acceptFile.jsp");
%>
<p>选择要上传的文件:<br>
<form action="<%=str%>" method="post" ENCTYPE="multipart/form-data">
<input type=FILE name="boy" size="45">
<br><input type="submit" name="g" value="提交">
</form>
</body>
</html>文件2:
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<body>
<% String str=response.encodeURL("acceptFile.jsp");
%>
<p>选择要上传的文件:<br>
<form action="<%=str%>" method="post" ENCTYPE="multipart/form-data">
<input type=FILE name="boy" size="45">
<br><input type="submit" name="g" value="提交">
</form>
</body>
</html>文件3:
<html>
<body>
<%String name=(String)session.getAttribute("Name");
if(name==null)
{ name="";}
out.print("<image src=http://localhost:8080/examples/temp/第四章/>"+name);
%>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<body>
<%try{
String tempFileName=(String)session.getId();
File f1=new File("F:/Apache Group/Tomcat 4.1/webapps/examples/temp/第四章",tempFileName);
FileOutputStream o=new FileOutputStream(f1);
InputStream in=request.getInputStream();
byte b[]=new byte[10000];
int n;
while((n=in.read(b))!=-1)
{
o.write(b,0,n);
}
o.close();
in.close();
RandomAccessFile random=new RandomAccessFile(f1,"r");
int second=1;
String secondLine=null;
while(second<=2)
{
secondLine=random.readLine();
second++;
}
int position=secondLine.lastIndexOf('\\');
String fileName=secondLine.substring(position+1,secondLine.length()-1);
random.seek(0);
long forthEndPosition=0;
int forth=1;
while((n=random.readByte())!=-1&&(forth<=4))
{
if(n=='\n')
{
forthEndPosition=random.getFilePointer();
forth++;
}
}
File f2=new File("F:/Apache Group/Tomcat 4.1/webapps/examples/temp/第四章",fileName);
session.setAttribute("Name",fileName);
RandomAccessFile random2=new RandomAccessFile(f2,"rw");
random.seek(random.length());
long endPosition=random.getFilePointer();
long =endPosition;
int j=1;
while((>=0)&&(j<=6))
{
--;
random.seek();
n=random.readByte();
if(n=='\n')
{
endPosition=random.getFilePointer();
j++;
}
}
random.seek(forthEndPosition);
long startPoint=random.getFilePointer();
while(startPoint<endPosition-1)
{
n=random.readByte();
random2.write(n);
startPoint=random.getFilePointer();
}
random2.close();
random.close();
f1.delete();
}
catch(IOException ee){}
out.print("文件已上传");
%>
<p>杳看上传的图像效果
<%String str=response.encodeURL("showImage.jsp");
%>
<form action="<%=str%>">
<input type=submit value="查看">
</form>
</body>
</html>
文件3中下面这句不对吧,
out.print("<image src=http://localhost:8080/examples/temp/第四章/>"+name);应该是out.print("<image src=http://localhost:8080/examples/temp/第四章/"+name+">"); 才对吧吧