|
отправка email+attachment через servlet/jsp - javamail
|
|||
---|---|---|---|
#18+
буду благодарен за любые комментарии, мысли, ссылки ... |
|||
:
Нравится:
Не нравится:
|
|||
05.08.2003, 19:20 |
|
отправка email+attachment через servlet/jsp - javamail
|
|||
---|---|---|---|
#18+
Use Java Mail Api or write yourself smtp client :)) http:://java.sun.com ... |
|||
:
Нравится:
Не нравится:
|
|||
06.08.2003, 03:47 |
|
отправка email+attachment через servlet/jsp - javamail
|
|||
---|---|---|---|
#18+
Проблема собственно вот в чем есть приложение, крутится под tomcat есть страничка Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9.
как получить этот файл из POST и засунуть его в DataSource ... |
|||
:
Нравится:
Не нравится:
|
|||
06.08.2003, 09:35 |
|
отправка email+attachment через servlet/jsp - javamail
|
|||
---|---|---|---|
#18+
<%@ page errorPage="error.jsp" %> <jsp:useBean id="prop" scope="page" class="java.util.Properties" /> <%@ page import="java.io.*,java.util.*,javax.servlet.*" %> <%! public String getBoundary(HttpServletRequest request,Properties prop) throws ServletException,IOException{ String boundary = null; Enumeration enum = request.getHeaderNames(); while(enum.hasMoreElements()){ String header = (String)enum.nextElement(); String hvalue = request.getHeader(header); prop.setProperty((header).toLowerCase(),hvalue); if( "content-type".equalsIgnoreCase(header) ){ int idx = hvalue.lastIndexOf("boundary="); if( idx != -1 ){ boundary= hvalue.substring( idx+9 , hvalue.length()); } } } return boundary; } public String getFileName(String secondline){ int len = secondline.length(); int idx = secondline.lastIndexOf("filename="); if( idx == -1 ) return null; String filename = secondline.substring( idx+10 , len-1); filename = filename.replace(`\\`,`/`); idx = filename.lastIndexOf("/"); idx = idx + 1; filename = filename.substring( idx ); return filename; } %> <% String DPATH = "C:\\temp\\file\\"; int ROUGHSIZE=1024; int MAXSIZE = 10; // Mega Byte String boundary = getBoundary(request,prop); if( boundary == null ){ boundary = prop.getProperty("boundary");// This statement line for HOTJAVABROWSER 3.0 }else{ boundary = "--"+boundary; } if( boundary == null ){ throw new Exception("BNF"); } Long contentsize = new Long(prop.getProperty("content-length","0")); int c; StringWriter st = new StringWriter(); if( contentsize.longValue() < 1L ){ throw new Exception("ZERO"); } long l = contentsize.longValue() - ROUGHSIZE; /* You can restrict upload file size in the following way 1. after uploaded u cannt find out file size then display error message 2. from contentsize it will give approximate size of file in bytes. based on this u can restrict uploading. */ int KB = 1024; int MB = 1024 * KB; int csize = (int)(l / MB); if( csize > MAXSIZE ){ throw new Exception("EL"); } ServletInputStream fin = request.getInputStream(); //Getting Start Boundary Line int cn; int count=0; while( (c=fin.read()) != -1 ){ if( c == `\r`) break; st.write(c); count++; } c=fin.read();//read new line String tboundary = st.getBuffer().toString(); tboundary=tboundary.trim(); if( ! tboundary.equalsIgnoreCase( boundary) ){ throw new Exception("BBNF"); } st.close(); st = null; st = new StringWriter(); //Getting File Information while( (c=fin.read()) != -1 ){ if( c == `\r` ) break; st.write(c); } c=fin.read();//read new line String secondline = st.getBuffer().toString(); String filename = getFileName(secondline); st.close(); st = null; st = new StringWriter(); //Read Content Type of File while( (c=fin.read()) != -1 ){ if( c == `\r` ) break; st.write( c ); } c=fin.read();//read new line //out.println( st.getBuffer().toString() ); //Read \r and \n character fin.read(); fin.read(); File newfile = null; FileOutputStream fout =null; try{ if( filename == null ) throw new FileNotFoundException("File Name not found"); newfile = new File(DPATH+filename); fout = new FileOutputStream( newfile ); }catch(FileNotFoundException fnexp){ fin.close(); throw new Exception("FNF"); } byte b[] = null; while( l > 1024L ){ b = new byte[1024]; fin.read(b,0,1024); fout.write(b); b=null; l -= 1024L; } if( l > 0 ){ b = new byte[(int)l]; fin.read(b,0,(int)l); fout.write(b); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); while( (c = fin.read()) != -1 ){ baos.write(c); } String laststring = baos.toString(); int idx = laststring.indexOf(boundary); b = baos.toByteArray(); if( idx > 2 ){ fout.write(b,0,idx-2); }else { fout.close(); newfile.delete(); throw new Exception("EBNF"); } fout.flush(); fout.close(); fin.close(); %> <html> <body> <TABLE> <TR> <TD>FileName</TD><TD><%=newfile.getName()%></TD> </TR> <TR> <TD>FileSize</TD><TD><%=newfile.length()%></TD> </TR> </TABLE> </body> </html> and the corresponding HTML code is : <html> <head> </head> <body> <form name="Test" method="post" action="upload.jsp" enctype="multipart/form-data"> <table width="75%" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#8B88AA"> <tr> <td> <blockquote> <p>To attach a file, type the path of the file or click on the "Browse" button to locate it in your computer.</p> </blockquote> </td> </tr> <tr> <td> <div align="center"><font size="2">Attachment :</font> <input type="File" name="picture" > </div> </td> </tr> <tr> <td> </td> </tr> <tr> <td height="17"> <blockquote> <p>Click on the "Upload File" button, after selecting the file.</p> </blockquote> </td> </tr> <tr> <td height="24"> <div align="center"> <input type="Submit" value="Upload File" name="Submit" > </div> </td> </tr> </table> </form> </html> [src][/src] ... |
|||
:
Нравится:
Не нравится:
|
|||
07.08.2003, 02:09 |
|
|
start [/forum/topic.php?fid=59&msg=32229483&tid=2154604]: |
0ms |
get settings: |
9ms |
get forum list: |
14ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
146ms |
get topic data: |
11ms |
get forum data: |
2ms |
get page messages: |
33ms |
get tp. blocked users: |
2ms |
others: | 18ms |
total: | 243ms |
0 / 0 |