仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 786|回复: 19
打印 上一主题 下一主题

[学习教程] JAVA网页设计JspSmart之upload组件源码及利用

[复制链接]
不帅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:34:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
诸如RMI,EJB等一些技术并不是你说的那么复杂,而是它们把一些复杂的工具封装成不复杂的工具了,理解这些工具是需要些时间。我问你,.net里有这些工具吗?要简单多少?。jsJspSmart之upload组件源码次要包含了5个java文件File.java
importjava.io.ByteArrayInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.math.BigInteger;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjavax.servlet.ServletException;
//Referencedclassesofpackagecom.jspsmart.upload:
//SmartUploadException,SmartUpload
publicclassFile
{
privateSmartUploadm_parent;
privateintm_startData;
privateintm_endData;
privateintm_size;
privateStringm_fieldname;
privateStringm_filename;
privateStringm_fileExt;
privateStringm_filePathName;
privateStringm_contentType;
privateStringm_contentDisp;
privateStringm_typeMime;
privateStringm_subTypeMime;
privateStringm_contentString;
privatebooleanm_isMissing;
publicstaticfinalintSAVEAS_AUTO=0;
publicstaticfinalintSAVEAS_VIRTUAL=1;
publicstaticfinalintSAVEAS_PHYSICAL=2;
File()
{
m_startData=0;
m_endData=0;
m_size=0;
m_fieldname=newString();
m_filename=newString();
m_fileExt=newString();
m_filePathName=newString();
m_contentType=newString();
m_contentDisp=newString();
m_typeMime=newString();
m_subTypeMime=newString();
m_contentString=newString();
m_isMissing=true;
}
publicvoidsaveAs(Strings)
throwsIOException,SmartUploadException
{
saveAs(s,0);
}
publicvoidsaveAs(Strings,inti)
throwsIOException,SmartUploadException
{
Strings1=newString();
s1=m_parent.getPhysicalPath(s,i);
if(s1==null)
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1140).");
try
{
java.io.Filefile=newjava.io.File(s1);
FileOutputStreamfileoutputstream=newFileOutputStream(file);
fileoutputstream.write(m_parent.m_binArray,m_startData,m_size);
fileoutputstream.close();
}
catch(IOExceptionioexception)
{
thrownewSmartUploadException("Filecantbesaved(1120).");
}
}
publicvoidfileToField(ResultSetresultset,Strings)
throwsServletException,IOException,SmartUploadException,SQLException
{
longl=0L;
inti=0x10000;
intj=0;
intk=m_startData;
if(resultset==null)
thrownewIllegalArgumentException("TheRecordSetcannotbenull(1145).");
if(s==null)
thrownewIllegalArgumentException("ThecolumnNamecannotbenull(1150).");
if(s.length()==0)
thrownewIllegalArgumentException("ThecolumnNamecannotbeempty(1155).");
l=BigInteger.valueOf(m_size).divide(BigInteger.valueOf(i)).longValue();
j=BigInteger.valueOf(m_size).mod(BigInteger.valueOf(i)).intValue();
try
{
for(inti1=1;(long)i1<l;i1++)
{
resultset.updateBinaryStream(s,newByteArrayInputStream(m_parent.m_binArray,k,i),i);
k=k!=0?k:1;
k=i1*i+m_startData;
}
if(j>0)
resultset.updateBinaryStream(s,newByteArrayInputStream(m_parent.m_binArray,k,j),j);
}
catch(SQLExceptionsqlexception)
{
byteabyte0[]=newbyte[m_size];
System.arraycopy(m_parent.m_binArray,m_startData,abyte0,0,m_size);
resultset.updateBytes(s,abyte0);
}
catch(Exceptionexception)
{
thrownewSmartUploadException("UnabletosavefileintheDataBase(1130).");
}
}
publicbooleanisMissing()
{
returnm_isMissing;
}
publicStringgetFieldName()
{
returnm_fieldname;
}
publicStringgetFileName()
{
returnm_filename;
}
publicStringgetFilePathName()
{
returnm_filePathName;
}
publicStringgetFileExt()
{
returnm_fileExt;
}
publicStringgetContentType()
{
returnm_contentType;
}
publicStringgetContentDisp()
{
returnm_contentDisp;
}
publicStringgetContentString()
{
Strings=newString(m_parent.m_binArray,m_startData,m_size);
returns;
}
publicStringgetTypeMIME()
throwsIOException
{
returnm_typeMime;
}
publicStringgetSubTypeMIME()
{
returnm_subTypeMime;
}
publicintgetSize()
{
returnm_size;
}
protectedintgetStartData()
{
returnm_startData;
}
protectedintgetEndData()
{
returnm_endData;
}
protectedvoidsetParent(SmartUploadsmartupload)
{
m_parent=smartupload;
}
protectedvoidsetStartData(inti)
{
m_startData=i;
}
protectedvoidsetEndData(inti)
{
m_endData=i;
}
protectedvoidsetSize(inti)
{
m_size=i;
}
protectedvoidsetIsMissing(booleanflag)
{
m_isMissing=flag;
}
protectedvoidsetFieldName(Strings)
{
m_fieldname=s;
}
protectedvoidsetFileName(Strings)
{
m_filename=s;
}
protectedvoidsetFilePathName(Strings)
{
m_filePathName=s;
}
protectedvoidsetFileExt(Strings)
{
m_fileExt=s;
}
protectedvoidsetContentType(Strings)
{
m_contentType=s;
}
protectedvoidsetContentDisp(Strings)
{
m_contentDisp=s;
}
protectedvoidsetTypeMIME(Strings)
{
m_typeMime=s;
}
protectedvoidsetSubTypeMIME(Strings)
{
m_subTypeMime=s;
}
publicbytegetBinaryData(inti)
{
if(m_startData+i>m_endData)
thrownewArrayIndexOutOfBoundsException("IndexOutofrange(1115).");
if(m_startData+i<=m_endData)
returnm_parent.m_binArray[m_startData+i];
else
return0;
}
}

Files.java
importjava.io.IOException;
importjava.util.*;
//Referencedclassesofpackagecom.jspsmart.upload:
//File,SmartUpload
publicclassFiles
{
privateSmartUploadm_parent;
privateHashtablem_files;
privateintm_counter;
Files()
{
m_files=newHashtable();
m_counter=0;
}
protectedvoidaddFile(Filefile)
{
if(file==null)
{
thrownewIllegalArgumentException("newFilecannotbenull.");
}else
{
m_files.put(newInteger(m_counter),file);
m_counter++;
return;
}
}
publicFilegetFile(inti)
{
if(i<0)
thrownewIllegalArgumentException("Filesindexcannotbeanegativevalue(1210).");
Filefile=(File)m_files.get(newInteger(i));
if(file==null)
thrownewIllegalArgumentException("Filesnameisinvalidordoesnotexist(1205).");
else
returnfile;
}
publicintgetCount()
{
returnm_counter;
}
publiclonggetSize()
throwsIOException
{
longl=0L;
for(inti=0;i<m_counter;i++)
l+=getFile(i).getSize();
returnl;
}
publicCollectiongetCollection()
{
returnm_files.values();
}
publicEnumerationgetEnumeration()
{
returnm_files.elements();
}
}

Request.java
importjava.util.Enumeration;
importjava.util.Hashtable;
publicclassRequest
{
privateHashtablem_parameters;
privateintm_counter;
Request()
{
m_parameters=newHashtable();
m_counter=0;
}
protectedvoidputParameter(Strings,Strings1)
{
if(s==null)
thrownewIllegalArgumentException("Thenameofanelementcannotbenull.");
if(m_parameters.containsKey(s))
{
Hashtablehashtable=(Hashtable)m_parameters.get(s);
hashtable.put(newInteger(hashtable.size()),s1);
}else
{
Hashtablehashtable1=newHashtable();
hashtable1.put(newInteger(0),s1);
m_parameters.put(s,hashtable1);
m_counter++;
}
}
publicStringgetParameter(Strings)
{
if(s==null)
thrownewIllegalArgumentException("Formsnameisinvalidordoesnotexist(1305).");
Hashtablehashtable=(Hashtable)m_parameters.get(s);
if(hashtable==null)
returnnull;
else
return(String)hashtable.get(newInteger(0));
}
publicEnumerationgetParameterNames()
{
returnm_parameters.keys();
}
publicString[]getParameterValues(Strings)
{
if(s==null)
thrownewIllegalArgumentException("Formsnameisinvalidordoesnotexist(1305).");
Hashtablehashtable=(Hashtable)m_parameters.get(s);
if(hashtable==null)
returnnull;
Stringas[]=newString[hashtable.size()];
for(inti=0;i<hashtable.size();i++)
as[i]=(String)hashtable.get(newInteger(i));
returnas;
}
}

SmartUploadException.java
publicclassSmartUploadExceptionextendsException
{
SmartUploadException(Strings)
{
super(s);
}
}

SmartUpload.java
importjava.io.*;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.Vector;
importjavax.servlet.*;
importjavax.servlet.http.*;
importjavax.servlet.jsp.JspWriter;
importjavax.servlet.jsp.PageContext;
//Referencedclassesofpackagecom.jspsmart.upload:
//Files,Request,SmartUploadException,File
publicclassSmartUpload
{
protectedbytem_binArray[];
protectedHttpServletRequestm_request;
protectedHttpServletResponsem_response;
protectedServletContextm_application;
privateintm_totalBytes;
privateintm_currentIndex;
privateintm_startData;
privateintm_endData;
privateStringm_boundary;
privatelongm_totalMaxFileSize;
privatelongm_maxFileSize;
privateVectorm_deniedFilesList;
privateVectorm_allowedFilesList;
privatebooleanm_denyPhysicalPath;
privatebooleanm_forcePhysicalPath;
privateStringm_contentDisposition;
publicstaticfinalintSAVE_AUTO=0;
publicstaticfinalintSAVE_VIRTUAL=1;
publicstaticfinalintSAVE_PHYSICAL=2;
privateFilesm_files;
privateRequestm_formRequest;
publicSmartUpload()
{
m_totalBytes=0;
m_currentIndex=0;
m_startData=0;
m_endData=0;
m_boundary=newString();
m_totalMaxFileSize=0L;
m_maxFileSize=0L;
m_deniedFilesList=newVector();
m_allowedFilesList=newVector();
m_denyPhysicalPath=false;
m_forcePhysicalPath=false;
m_contentDisposition=newString();
m_files=newFiles();
m_formRequest=newRequest();
}
publicfinalvoidinit(ServletConfigservletconfig)
throwsServletException
{
m_application=servletconfig.getServletContext();
}
publicvoidservice(HttpServletRequesthttpservletrequest,HttpServletResponsehttpservletresponse)
throwsServletException,IOException
{
m_request=httpservletrequest;
m_response=httpservletresponse;
}
publicfinalvoidinitialize(ServletConfigservletconfig,HttpServletRequesthttpservletrequest,HttpServletResponsehttpservletresponse)
throwsServletException
{
m_application=servletconfig.getServletContext();
m_request=httpservletrequest;
m_response=httpservletresponse;
}
publicfinalvoidinitialize(PageContextpagecontext)
throwsServletException
{
m_application=pagecontext.getServletContext();
m_request=(HttpServletRequest)pagecontext.getRequest();
m_response=(HttpServletResponse)pagecontext.getResponse();
}
publicfinalvoidinitialize(ServletContextservletcontext,HttpSessionhttpsession,HttpServletRequesthttpservletrequest,HttpServletResponsehttpservletresponse,JspWriterjspwriter)
throwsServletException
{
m_application=servletcontext;
m_request=httpservletrequest;
m_response=httpservletresponse;
}
publicvoidupload()
throwsServletException,IOException,SmartUploadException
{
inti=0;
booleanflag=false;
longl=0L;
booleanflag1=false;
Strings=newString();
Strings2=newString();
Strings4=newString();
Strings5=newString();
Strings6=newString();
Strings7=newString();
Strings8=newString();
Strings9=newString();
Strings10=newString();
booleanflag2=false;
m_totalBytes=m_request.getContentLength();
m_binArray=newbyte[m_totalBytes];
intj;
for(;i<m_totalBytes;i+=j)
try
{
m_request.getInputStream();
j=m_request.getInputStream().read(m_binArray,i,m_totalBytes-i);
}
catch(Exceptionexception)
{
thrownewSmartUploadException("Unabletoupload.");
}
for(;!flag1&&m_currentIndex<m_totalBytes;m_currentIndex++)
if(m_binArray[m_currentIndex]==13)
flag1=true;
else
m_boundary=m_boundary+(char)m_binArray[m_currentIndex];
if(m_currentIndex==1)
return;
for(m_currentIndex++;m_currentIndex<m_totalBytes;m_currentIndex=m_currentIndex+2)
{
Strings1=getDataHeader();
m_currentIndex=m_currentIndex+2;
booleanflag3=s1.indexOf("filename")>0;
Strings3=getDataFieldValue(s1,"name");
if(flag3)
{
s6=getDataFieldValue(s1,"filename");
s4=getFileName(s6);
s5=getFileExt(s4);
s7=getContentType(s1);
s8=getContentDisp(s1);
s9=getTypeMIME(s7);
s10=getSubTypeMIME(s7);
}
getDataSection();
if(flag3&&s4.length()>0)
{
if(m_deniedFilesList.contains(s5))
thrownewSecurityException("Theextensionofthefileisdeniedtobeuploaded(1015).");
if(!m_allowedFilesList.isEmpty()&&!m_allowedFilesList.contains(s5))
thrownewSecurityException("Theextensionofthefileisnotallowedtobeuploaded(1010).");
if(m_maxFileSize>0L&&(long)((m_endData-m_startData)+1)>m_maxFileSize)
thrownewSecurityException("Sizeexceededforthisfile:"+s4+"(1105).");
l+=(m_endData-m_startData)+1;
if(m_totalMaxFileSize>0L&&l>m_totalMaxFileSize)
thrownewSecurityException("TotalFileSizeexceeded(1110).");
}
if(flag3)
{
com.facet.jspsmart.upload.Filefile=newcom.facet.jspsmart.upload.File();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
file.setIsMissing(s6.length()==0);
file.setContentType(s7);
file.setContentDisp(s8);
file.setTypeMIME(s9);
file.setSubTypeMIME(s10);
if(s7.indexOf("application/x-macbinary")>0)
m_startData=m_startData+128;
file.setSize((m_endData-m_startData)+1);
file.setStartData(m_startData);
file.setEndData(m_endData);
m_files.addFile(file);
}else
{
Strings11=newString(m_binArray,m_startData,(m_endData-m_startData)+1);
m_formRequest.putParameter(s3,s11);
}
if((char)m_binArray[m_currentIndex+1]==-)
break;
}
}
publicintsave(Strings)
throwsServletException,IOException,SmartUploadException
{
returnsave(s,0);
}
publicintsave(Strings,inti)
throwsServletException,IOException,SmartUploadException
{
intj=0;
if(s==null)
s=m_application.getRealPath("/");
if(s.indexOf("/")!=-1)
{
if(s.charAt(s.length()-1)!=/)
s=s+"/";
}else
if(s.charAt(s.length()-1)!=)
s=s+"";
for(intk=0;k<m_files.getCount();k++)
if(!m_files.getFile(k).isMissing())
{
m_files.getFile(k).saveAs(s+m_files.getFile(k).getFileName(),i);
j++;
}
returnj;
}
publicintgetSize()
{
returnm_totalBytes;
}
publicbytegetBinaryData(inti)
{
bytebyte0;
try
{
byte0=m_binArray[i];
}
catch(Exceptionexception)
{
thrownewArrayIndexOutOfBoundsException("Indexoutofrange(1005).");
}
returnbyte0;
}
publicFilesgetFiles()
{
returnm_files;
}
publicRequestgetRequest()
{
returnm_formRequest;
}
publicvoiddownloadFile(Strings)
throwsServletException,IOException,SmartUploadException
{
downloadFile(s,null,null);
}
publicvoiddownloadFile(Strings,Strings1)
throwsServletException,IOException,SmartUploadException,SmartUploadException
{
downloadFile(s,s1,null);
}
publicvoiddownloadFile(Strings,Strings1,Strings2)
throwsServletException,IOException,SmartUploadException
{
downloadFile(s,s1,s2,65000);
}
publicvoiddownloadFile(Strings,Strings1,Strings2,inti)
throwsServletException,IOException,SmartUploadException
{
if(s==null)
thrownewIllegalArgumentException("File"+s+"notfound(1040).");
if(s.equals(""))
thrownewIllegalArgumentException("File"+s+"notfound(1040).");
if(!isVirtual(s)&&m_denyPhysicalPath)
thrownewSecurityException("Physicalpathisdenied(1035).");
if(isVirtual(s))
s=m_application.getRealPath(s);
java.io.Filefile=newjava.io.File(s);
FileInputStreamfileinputstream=newFileInputStream(file);
longl=file.length();
booleanflag=false;
intk=0;
byteabyte0[]=newbyte[i];
if(s1==null)
m_response.setContentType("application/x-msdownload");
else
if(s1.length()==0)
m_response.setContentType("application/x-msdownload");
else
m_response.setContentType(s1);
m_response.setContentLength((int)l);
m_contentDisposition=m_contentDisposition!=null?m_contentDisposition:"attachment;";
if(s2==null)
m_response.setHeader("Content-Disposition",m_contentDisposition+"filename="+getFileName(s));
else
if(s2.length()==0)
m_response.setHeader("Content-Disposition",m_contentDisposition);
else
m_response.setHeader("Content-Disposition",m_contentDisposition+"filename="+s2);
while((long)k<l)
{
intj=fileinputstream.read(abyte0,0,i);
k+=j;
m_response.getOutputStream().write(abyte0,0,j);
}
fileinputstream.close();
}
publicvoiddownloadField(ResultSetresultset,Strings,Strings1,Strings2)
throwsServletException,IOException,SQLException
{
if(resultset==null)
thrownewIllegalArgumentException("TheRecordSetcannotbenull(1045).");
if(s==null)
thrownewIllegalArgumentException("ThecolumnNamecannotbenull(1050).");
if(s.length()==0)
thrownewIllegalArgumentException("ThecolumnNamecannotbeempty(1055).");
byteabyte0[]=resultset.getBytes(s);
if(s1==null)
m_response.setContentType("application/x-msdownload");
else
if(s1.length()==0)
m_response.setContentType("application/x-msdownload");
else
m_response.setContentType(s1);
m_response.setContentLength(abyte0.length);
if(s2==null)
m_response.setHeader("Content-Disposition","attachment;");
else
if(s2.length()==0)
m_response.setHeader("Content-Disposition","attachment;");
else
m_response.setHeader("Content-Disposition","attachment;filename="+s2);
m_response.getOutputStream().write(abyte0,0,abyte0.length);
}
publicvoidfieldToFile(ResultSetresultset,Strings,Strings1)
throwsServletException,IOException,SmartUploadException,SQLException
{
try
{
if(m_application.getRealPath(s1)!=null)
s1=m_application.getRealPath(s1);
InputStreaminputstream=resultset.getBinaryStream(s);
FileOutputStreamfileoutputstream=newFileOutputStream(s1);
inti;
while((i=inputstream.read())!=-1)
fileoutputstream.write(i);
fileoutputstream.close();
}
catch(Exceptionexception)
{
thrownewSmartUploadException("UnabletosavefilefromtheDataBase(1020).");
}
}
privateStringgetDataFieldValue(Strings,Strings1)
{
Strings2=newString();
Strings3=newString();
inti=0;
booleanflag=false;
booleanflag1=false;
booleanflag2=false;
s2=s1+"="+";
i=s.indexOf(s2);
if(i>0)
{
intj=i+s2.length();
intk=j;
s2=""";
intl=s.indexOf(s2,j);
if(k>0&&l>0)
s3=s.substring(k,l);
}
returns3;
}
privateStringgetFileExt(Strings)
{
Strings1=newString();
inti=0;
intj=0;
if(s==null)
returnnull;
i=s.lastIndexOf(46)+1;
j=s.length();
s1=s.substring(i,j);
if(s.lastIndexOf(46)>0)
returns1;
else
return"";
}
privateStringgetContentType(Strings)
{
Strings1=newString();
Strings2=newString();
inti=0;
booleanflag=false;
s1="Content-Type:";
i=s.indexOf(s1)+s1.length();
if(i!=-1)
{
intj=s.length();
s2=s.substring(i,j);
}
returns2;
}
privateStringgetTypeMIME(Strings)
{
Strings1=newString();
inti=0;
i=s.indexOf("/");
if(i!=-1)
returns.substring(1,i);
else
returns;
}
privateStringgetSubTypeMIME(Strings)
{
Strings1=newString();
inti=0;
booleanflag=false;
i=s.indexOf("/")+1;
if(i!=-1)
{
intj=s.length();
returns.substring(i,j);
}else
{
returns;
}
}
privateStringgetContentDisp(Strings)
{
Strings1=newString();
inti=0;
intj=0;
i=s.indexOf(":")+1;
j=s.indexOf(";");
s1=s.substring(i,j);
returns1;
}
privatevoidgetDataSection()
{
booleanflag=false;
Strings=newString();
inti=m_currentIndex;
intj=0;
intk=m_boundary.length();
m_startData=m_currentIndex;
m_endData=0;
while(i<m_totalBytes)
if(m_binArray[i]==(byte)m_boundary.charAt(j))
{
if(j==k-1)
{
m_endData=((i-k)+1)-3;
break;
}
i++;
j++;
}else
{
i++;
j=0;
}
m_currentIndex=m_endData+k+3;
}
privateStringgetDataHeader()
{
inti=m_currentIndex;
intj=0;
booleanflag=false;
for(booleanflag1=false;!flag1;)
if(m_binArray[m_currentIndex]==13&&m_binArray[m_currentIndex+2]==13)
{
flag1=true;
j=m_currentIndex-1;
m_currentIndex=m_currentIndex+2;
}else
{
m_currentIndex++;
}
Strings=newString(m_binArray,i,(j-i)+1);
returns;
}
privateStringgetFileName(Strings)
{
Strings1=newString();
Strings2=newString();
inti=0;
booleanflag=false;
booleanflag1=false;
booleanflag2=false;
i=s.lastIndexOf(47);
if(i!=-1)
returns.substring(i+1,s.length());
i=s.lastIndexOf(92);
if(i!=-1)
returns.substring(i+1,s.length());
else
returns;
}
publicvoidsetDeniedFilesList(Strings)
throwsServletException,IOException,SQLException
{
Strings1="";
if(s!=null)
{
Strings2="";
for(inti=0;i<s.length();i++)
if(s.charAt(i)==,)
{
if(!m_deniedFilesList.contains(s2))
m_deniedFilesList.addElement(s2);
s2="";
}else
{
s2=s2+s.charAt(i);
}
if(s2!="")
m_deniedFilesList.addElement(s2);
}else
{
m_deniedFilesList=null;
}
}
publicvoidsetAllowedFilesList(Strings)
{
Strings1="";
if(s!=null)
{
Strings2="";
for(inti=0;i<s.length();i++)
if(s.charAt(i)==,)
{
if(!m_allowedFilesList.contains(s2))
m_allowedFilesList.addElement(s2);
s2="";
}else
{
s2=s2+s.charAt(i);
}
if(s2!="")
m_allowedFilesList.addElement(s2);
}else
{
m_allowedFilesList=null;
}
}
publicvoidsetDenyPhysicalPath(booleanflag)
{
m_denyPhysicalPath=flag;
}
publicvoidsetForcePhysicalPath(booleanflag)
{
m_forcePhysicalPath=flag;
}
publicvoidsetContentDisposition(Strings)
{
m_contentDisposition=s;
}
publicvoidsetTotalMaxFileSize(longl)
{
m_totalMaxFileSize=l;
}
publicvoidsetMaxFileSize(longl)
{
m_maxFileSize=l;
}
protectedStringgetPhysicalPath(Strings,inti)
throwsIOException
{
Strings1=newString();
Strings2=newString();
Strings3=newString();
booleanflag=false;
s3=System.getProperty("file.separator");
if(s==null)
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1140).");
if(s.equals(""))
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1140).");
if(s.lastIndexOf("")>=0)
{
s1=s.substring(0,s.lastIndexOf(""));
s2=s.substring(s.lastIndexOf("")+1);
}
if(s.lastIndexOf("/")>=0)
{
s1=s.substring(0,s.lastIndexOf("/"));
s2=s.substring(s.lastIndexOf("/")+1);
}
s1=s1.length()!=0?s1:"/";
java.io.Filefile=newjava.io.File(s1);
if(file.exists())
flag=true;
if(i==0)
{
if(isVirtual(s1))
{
s1=m_application.getRealPath(s1);
if(s1.endsWith(s3))
s1=s1+s2;
else
s1=s1+s3+s2;
returns1;
}
if(flag)
{
if(m_denyPhysicalPath)
thrownewIllegalArgumentException("Physicalpathisdenied(1125).");
else
returns;
}else
{
thrownewIllegalArgumentException("Thispathdoesnotexist(1135).");
}
}
if(i==1)
{
if(isVirtual(s1))
{
s1=m_application.getRealPath(s1);
if(s1.endsWith(s3))
s1=s1+s2;
else
s1=s1+s3+s2;
returns1;
}
if(flag)
thrownewIllegalArgumentException("Thepathisnotavirtualpath.");
else
thrownewIllegalArgumentException("Thispathdoesnotexist(1135).");
}
if(i==2)
{
if(flag)
if(m_denyPhysicalPath)
thrownewIllegalArgumentException("Physicalpathisdenied(1125).");
else
returns;
if(isVirtual(s1))
thrownewIllegalArgumentException("Thepathisnotaphysicalpath.");
else
thrownewIllegalArgumentException("Thispathdoesnotexist(1135).");
}else
{
returnnull;
}
}
publicvoiduploadInFile(Strings)
throwsIOException,SmartUploadException
{
inti=0;
intj=0;
booleanflag=false;
if(s==null)
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1025).");
if(s.length()==0)
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1025).");
if(!isVirtual(s)&&m_denyPhysicalPath)
thrownewSecurityException("Physicalpathisdenied(1035).");
i=m_request.getContentLength();
m_binArray=newbyte[i];
intk;
for(;j<i;j+=k)
try
{
k=m_request.getInputStream().read(m_binArray,j,i-j);
}
catch(Exceptionexception)
{
thrownewSmartUploadException("Unabletoupload.");
}
if(isVirtual(s))
s=m_application.getRealPath(s);
try
{
java.io.Filefile=newjava.io.File(s);
FileOutputStreamfileoutputstream=newFileOutputStream(file);
fileoutputstream.write(m_binArray);
fileoutputstream.close();
}
catch(Exceptionexception1)
{
thrownewSmartUploadException("TheFormcannotbesavedinthespecifiedfile(1030).");
}
}
privatebooleanisVirtual(Strings)
{
if(m_application.getRealPath(s)!=null)
{
java.io.Filefile=newjava.io.File(m_application.getRealPath(s));
returnfile.exists();
}else
{
returnfalse;
}
}
}

jspsmart的利用
上传
//新建一个SmartUpload对象
SmartUploadsu=newSmartUpload();
//上传初始化
su.initialize(pageContext);
//限定每一个上传文件的最年夜长度。
su.setMaxFileSize(10000);
//限定总上传数据的长度。
su.setTotalMaxFileSize(20000);
//设定同意上传的文件(经由过程扩大名限定),仅同意doc,txt文件。
su.setAllowedFilesList("doc,txt");
//设定克制上传的文件(经由过程扩大名限定),克制上传带有exe,bat,
//jsp,htm,html扩大名的文件和没有扩大名的文件。
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
//上传文件
su.upload();
//将上传文件全体保留到指定目次
intcount=su.save("/upload");

下载
//新建一个SmartUpload对象
SmartUploadsu=newSmartUpload();
//初始化
su.initialize(pageContext);
//设定contentDisposition为null以克制扫瞄器主动翻开文件,
//包管点击链接后是下载文件。若不设定,则下载的文件扩大名为
//doc时,扫瞄器将主动用word翻开它。扩大名为pdf时,
//扫瞄器将用acrobat翻开。
su.setContentDisposition(null);
//下载文件
su.downloadFile("/upload/test.doc");



你通过从书的数量和开发周期及运行速度来证明:net和ruby要比java简单。
沙发
发表于 2015-1-21 10:16:22 | 只看该作者
我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。
山那边是海 该用户已被删除
板凳
发表于 2015-1-30 14:53:22 | 只看该作者
是一种使网页(Web Page)产生生动活泼画面的语言
不帅 该用户已被删除
地板
 楼主| 发表于 2015-2-9 22:57:40 | 只看该作者
科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
精灵巫婆 该用户已被删除
5#
发表于 2015-2-9 23:32:42 | 只看该作者
至于JDBC,就不用我多说了,你如果用java编过存取数据库的程序,就应该很熟悉。还有,如果你要用Java编发送电子邮件的程序,你就得看看Javamail 了。
老尸 该用户已被删除
6#
发表于 2015-2-10 04:27:26 | 只看该作者
Java是一个纯的面向对象的程序设计语言,它继承了 C++语言面向对象技术的核心。Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)
小女巫 该用户已被删除
7#
发表于 2015-2-28 19:43:47 | 只看该作者
我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。
海妖 该用户已被删除
8#
发表于 2015-3-1 10:11:57 | 只看该作者
吧,现在很流行的Structs就是它的一种实现方式,不过Structs用起来实在是很繁,我们只要学习其精髓即可,我们完全可以设计自己的MVC结构。然后你再研究一下软件Refactoring (重构)和极限XP编程,相信你又会上一个台阶。 做完这些,你不如整理一下你的Java代码,把那些经典的程序和常见的应用整理出来,再精心打造一番,提高其重用性和可扩展性。你再找几个志同道合的朋友成立一个工作室吧
若相依 该用户已被删除
9#
发表于 2015-3-2 15:36:16 | 只看该作者
J2SE开发桌面应用软件比起 VC,VB,DEPHI这些传统开发语言来说,优势好象并不明显。J2ME对于初学者来说,好象又有点深奥,而且一般开发者很难有开发环境。
乐观 该用户已被删除
10#
发表于 2015-3-2 20:24:07 | 只看该作者
还好,SUN提供了Javabean可以把你的JSP中的 Java代码封装起来,便于调用也便于重用。
只想知道 该用户已被删除
11#
发表于 2015-3-8 00:49:23 | 只看该作者
Pet Store.(宠物店)是SUN公司为了演示其J2EE编程规范而推出的开放源码的程序,应该很具有权威性,想学J2EE和EJB的朋友不要 错过了。
简单生活 该用户已被删除
12#
发表于 2015-3-11 14:44:19 | 只看该作者
你快去找一份Java的编程工作来做吧(如果是在校学生可以去做兼职啊),在实践中提高自己,那才是最快的。不过你得祈祷在公司里碰到一个高手,而且他 还愿意不厌其烦地教你,这样好象有点难哦!还有一个办法就是读开放源码的程序了。我们知道开放源码大都出自高手,他们设计合理,考虑周到,再加上有广大的程序员参与,代码的价值自然是字字珠叽,铿锵有力(对不起,偶最近《金装四大才子》看多了)。
谁可相欹 该用户已被删除
13#
发表于 2015-3-18 19:50:56 | 只看该作者
是一种语言,用以产生「小应用程序(Applet(s))
第二个灵魂 该用户已被删除
14#
发表于 2015-3-26 12:58:41 | 只看该作者
关于设计模式的资料,还是向大家推荐banq的网站 [url]http://www.jdon.com/[/url],他把GOF的23种模式以通俗易懂的方式诠释出来,纯Java描述,真是经典中的经典。
兰色精灵 该用户已被删除
15#
发表于 2015-4-13 14:23:59 | 只看该作者
如果你学过HTML,那么事情要好办的多,如果没有,那你快去补一补HTML基础吧。其实JSP中的Java语法也不多,它更象一个脚本语言,有点象ASP。
金色的骷髅 该用户已被删除
16#
发表于 2015-4-22 05:49:47 | 只看该作者
所以现在应用最广泛又最好学的就是J2EE了。 J2EE又包括许多组件,如Jsp,Servlet,JavaBean,EJB,JDBC,JavaMail等。要学习起来可不是一两天的事。那么又该如何学习J2EE呢?当然Java语法得先看一看的,I/O包,Util包,Lang包你都熟悉了吗?然后再从JSP学起。
小妖女 该用户已被删除
17#
发表于 2015-4-23 02:10:57 | 只看该作者
你可以去承接一些项目做了,一开始可能有些困难,可是你有技术积累,又考虑周全,接下项目来可以迅速作完,相信大家以后都会来找你的,所以Money就哗啦啦的。。。。。。
柔情似水 该用户已被删除
18#
发表于 2015-5-5 05:50:41 | 只看该作者
关于设计模式的资料,还是向大家推荐banq的网站 [url]http://www.jdon.com/[/url],他把GOF的23种模式以通俗易懂的方式诠释出来,纯Java描述,真是经典中的经典。
蒙在股里 该用户已被删除
19#
发表于 2015-5-6 15:11:07 | 只看该作者
任职于太阳微系统的詹姆斯·高斯林等人于1990年代初开发Java语言的雏形,最初被命名为Oak,目标设置在家用电器等小型系统的程序语言
若天明 该用户已被删除
20#
发表于 2015-6-12 04:56:55 | 只看该作者
至于JDBC,就不用我多说了,你如果用java编过存取数据库的程序,就应该很熟悉。还有,如果你要用Java编发送电子邮件的程序,你就得看看Javamail 了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-9 07:27

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表