2005/10/31
[Troubleshooting] SQLException: IO 異常: The Network Adapter could not establish the connection
SQLException: IO 異常: The Network Adapter could not establish the connection
成因
1. 資料庫沒有開啟, 所以無法連接上
2. 因為防火牆的原因, 該台連不上DBMS Server, 可先ping看看可否ping的到, ex. ping xxx.xxx.xxx.xxx 1521
2005/10/30
[Troubleshooting] 530 Sorry, no ANONYMOUS access allowed
用Server-U架起一個FTP Server,建立username=ftp, password=ftptest
此時用其他的ftp連線工具連線的時候,會出現此錯誤訊息: 530 Sorry, no ANONYMOUS access allowed
原因
因為ftp是保留字,不可以將其當成username,要將username改成其他名字即可
2005/10/28
[Info] JavaMail
Here has a reference link:
Sending Email with Spring mail abstraction layer
Here has sample code which write by me:
package albert.guo.util;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
/**
*
* @author Albert
*
*/
public class MailUtil {
private String addr[];
private String subject;
private String text;
private String host;
private String filepath;
private String filename;
private ArrayList fileList;
public MailUtil(String iAddr[], String iSubject, String iText, String iHost){
this.addr = iAddr;
this.subject = iSubject;
this.text = iText;
this.host = iHost;
}
public MailUtil(String iAddr[], String iSubject, String iText, String iHost,
ArrayList iFileList){
this.addr = iAddr;
this.subject = iSubject;
this.text = iText;
this.host = iHost;
this.fileList = iFileList;
}
/*
* 發送mail(不含附加檔案)
*/
public void sendMsg(){
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(this.addr);
msg.setSubject(this.subject);
msg.setText(this.text);
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(this.host);
mailSender.send(msg);
}
/*
* 發送mail(含附加檔案)
*/
public void sendMsgAndAttachment(){
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(this.host);
MimeMessage message = sender.createMimeMessage();
try {
//use the true flag to indicate you need a multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(this.addr);
helper.setSubject(this.subject);
helper.setText(this.text);
for(int i=0; i<this.fileList.size(); i++){
HashMap attachment = (HashMap)fileList.get(i);
String filepath = (String)attachment.get("filepath");
String filename = (String)attachment.get("filename");
helper.addAttachment(filename, new File(filepath+filename));
}
sender.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String addr[] = new String [] {"albertg@systex.com.tw"};
//MailUtil mailUtil = new MailUtil(addr, "標題", "內容\n啦啦啦", "mail.systex.com.tw");
//mailUtil.sendMsg();
ArrayList list = new ArrayList();
HashMap hm1 = new HashMap();
hm1.put("filepath", "C:/");
hm1.put("filename","test.doc");
HashMap hm2 = new HashMap();
hm2.put("filepath", "C:/");
hm2.put("filename", "LiveABC.Log");
list.add(hm1);
list.add(hm2);
MailUtil mailUtil = new MailUtil(addr, "標題", "內容\n啦啦啦", "mail.systex.com.tw",
list);
mailUtil.sendMsgAndAttachment();
}
}
2005/10/24
2005/10/20
[Troubleshoot] JDBC Connection Leak
在JSP中設定ErrorPage時,發生跳轉,來不及關閉連線
程式的錯誤處理非在finally區塊關閉連線
緩解方式
設定InactiveConnectionTimeoutSeconds時間
最終一定要修復程式中的問題
2005/10/07
[Info] 如何在IE中直接打開WORD等文件
如何在一个WEB APPLICATION中打開WORD,EXCEL等類型的文件?
ans.
為了讓能在IE流覽器中自動打開的設置:需要在WEB.XML中進行如下的設置:在WEB.XML中添加<mime-mapping>,其中:
<extension>:
文件的副檔名
<mime-type>:
除了該類型檔的可執行檔,同WINDOW註冊表中的
/HKEY_CLASSES_ROOT下該類檔的Content
Type 的值一樣.
如能在IE中自動打開DOC,XLS,PDF檔的配置如下:
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun
Microsystems, Inc.//DTD Web Application 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/msexcel</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
</web-app>