導航:首頁 > 編程語言 > javacommonvalidate

javacommonvalidate

發布時間:2024-10-04 15:29:52

❶ 怎樣用java開發ftp客戶端

package zn.ccfccb.util;
import hkrt.b2b.view.util.Log;
import hkrt.b2b.view.util.ViewUtil;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import zn.ccfccb.util.CCFCCBUtil;
import zn.ccfccb.util.ZipUtilAll;

public class CCFCCBFTP {

/**
* 上傳文件
*
* @param fileName
* @param plainFilePath 明文文件路徑路徑
* @param filepath
* @return
* @throws Exception
*/
public static String fileUploadByFtp(String plainFilePath, String fileName, String filepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FTPClient ftpClient = new FTPClient();
String bl = "false";
try {
fis = new FileInputStream(plainFilePath);
bos = new ByteArrayOutputStream(fis.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fis.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
Log.info("加密上傳文件開始");
Log.info("連接遠程上傳伺服器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);
ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);
ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSword);
// Log.info("連接遠程上傳伺服器"+"192.168.54.106:"+2021);
// ftpClient.connect("192.168.54.106", 2021);
// ftpClient.login("hkrt-CCFCCBHK", "3OLJheziiKnkVcu7Sigz");
FTPFile[] fs;
fs = ftpClient.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(filepath)) {
bl="true";
ftpClient.changeWorkingDirectory("/"+filepath+"");
}
}
Log.info("檢查文件路徑是否存在:/"+filepath);
if("false".equals(bl)){
ViewUtil.dataSEErrorPerformedCommon( "查詢文件路徑不存在:"+"/"+filepath);
return bl;
}
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
// 設置文件類型(二進制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile(fileName, fis);
Log.info("上傳文件成功:"+fileName+"。文件保存路徑:"+"/"+filepath+"/");
return bl;
} catch (Exception e) {
throw e;
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
}

}

/**
*下載並解壓文件
*
* @param localFilePath
* @param fileName
* @param routeFilepath
* @return
* @throws Exception
*/
public static String fileDownloadByFtp(String localFilePath, String fileName,String routeFilepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FileOutputStream fos = null;
FTPClient ftpClient = new FTPClient();
String SFP = System.getProperty("file.separator");
String bl = "false";
try {
Log.info("下載並解密文件開始");
Log.info("連接遠程下載伺服器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);
ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);
ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);
// ftpClient.connect(CMBCUtil.CMBCHOSTNAME, 2021);
// ftpClient.login(CMBCUtil.CMBCLOGINNAME, CMBCUtil.CMBCLOGINPASSWORD);
FTPFile[] fs;

ftpClient.makeDirectory(routeFilepath);
ftpClient.changeWorkingDirectory(routeFilepath);
bl = "false";
fs = ftpClient.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(fileName)) {
bl = "true";
Log.info("下載文件開始。");
ftpClient.setBufferSize(1024);
// 設置文件類型(二進制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
InputStream is = ftpClient.retrieveFileStream(fileName);
bos = new ByteArrayOutputStream(is.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = is.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
fos = new FileOutputStream(localFilePath+SFP+fileName);
fos.write(bos.toByteArray());
Log.info("下載文件結束:"+localFilePath);
}
}
Log.info("檢查文件是否存:"+fileName+" "+bl);
if("false".equals(bl)){
ViewUtil.dataSEErrorPerformedCommon("查詢無結果,請稍後再查詢。");
return bl;
}
return bl;
} catch (Exception e) {
throw e;
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
Log.info(e.getLocalizedMessage(), e);
}
}
}
}

// 調用樣例:
public static void main(String[] args) {
try {
// 密鑰/res/20150228
// ZipUtilAll.unZip(new File(("D:/123/123.zip")), "D:/123/");
// ZipDemo1232.unZip(new File(("D:/123/123.zip")), "D:/123/");
// 明文文件路徑
String plainFilePath = "D:/req_20150204_0011.txt";
// 密文文件路徑
String secretFilePath = "req_20150204_00134.txt";
// 加密
// encodeAESFile(key, plainFilePath, secretFilePath);
fileDownloadByFtp("D://123.zip","123.zip","req/20150228");
ZipUtilAll.unZip("D://123.zip", "D:/123/李筱/");
// 解密
plainFilePath = "D:/123.sql";
// secretFilePath = "D:/test11111.sql";
// decodeAESFile(key, plainFilePath, secretFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}

}

❷ java apache validator 校驗順序問題

肯定有順序了。從前至後啊。但是這個你也可以設置啊。validateor里,有一個depend on 屬性,這個屬性就是說,你當然這個校驗依賴於哪一個,如果有這個屬性的話,他就會先執行依懶的那個校驗的啊。

默認的都是你的XML的欄位順序啊。這個是肯定的吧。不可能隨機的。

❸ eclipse編輯js能卡出翔來怎麼解決求解惑

使用Eclipse編輯jsp、js文件時,經常出現卡死現象,在網上網路了N次,經過N次優化調整後,卡死現象逐步好轉,具體那個方法起到作用,不太好講。將所有用過的方法羅列如下:

1、取消驗證
windows–>perferences–>validation
把 除了manual 下面的全部點掉,build下只留 classpath dependency Validator

2、關閉拼寫檢查
windows–>perferences–>general–> editors->Text Editors->spelling

3、對於MyEclipse來講,修改JSP頁面時的編輯工具
Window > perferences > General > Editors > File Associations >
在File types 中選擇 *.jsp > 在Associated editors 中將"MyEclipse JSP Editor"設置為默認。

4、杜絕jar包訪問網路
當用eclipse或myeclipse編輯JSP時,使用智能提示將可能導致ide卡死。
這是因為eclipse提示時會根據JAR包指定的javadoc location訪問網路。
解決方法:window-->preferences-->java-->installed JREs,編輯使用的jre,把rt.jar和charsets.jar的javadoc location設置為空(none)即可。當然也可以去下載javadoc到本機,進行相關設置也可以解決。
另外:把自己項目中所有用到的jar包,都作同樣處理。

5、修改打開鏈接的快捷鍵
最近在MyEclipse中編輯代碼時,使用快捷鍵進行復制粘貼,經常會導致編輯器短暫的停頓,游標不跟隨,居然反應不過來,幾近假死。
想來想去應該是編輯上的什麼配置或者是IDE的什麼功能導致,於是進入Preferences查找edit功能,進行一個個的測試,最後發現原來是代碼的超鏈功能導致。
進入方法:Window -> Preferences -> General -> Editors -> Text Editors -> Hyperlinking
把超鏈的快捷鍵改為其他鍵比如Alt(不能改為shift)
說明:在Eclipse中,經常可以使用Ctrl+滑鼠單擊,可以直接將編輯界面引導到相關的方法,屬性,或者類。
這個功能確實非常好用,但是由於復制粘貼的功能快捷鍵也是Ctrl,以致我在快速進行操作的時候,Eclipse反應不過來,無法分析我的操作,現在只需要改變一個其他的快捷


6、修改項目的.project文件
eclipse中默認js編輯器非常慢,尤其在拷貝粘貼代碼時的解決方法
使用的是官網標准版的eclipse3.9 for javaEE未裝任何插件,寫JS時卡的簡直無法忍受,嘗試去掉所有的validate,包括菜單和項目屬性中的都無作用,後來在項目根目錄..project中發現以下紅色行居然Validator都還在,把紅色對應的配置段全部刪去後,問題解決,編輯JS再也不似蝸牛了.

<buildSpec>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.molecore.MoleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>


7、調整Eclipse運行內存。
在eclipse的安裝目錄下用EditPlus編輯eclipse.ini文件,將其中的參數改成:
第一個版本
-vmargs-Dosgi.requiredJavaVersion=1.6
-Xms512m
-Xmx512m
-XX:PermSize=256M
-XX:MaxPermSize=256M
-XX:-UseGCOverheadLimit
第二個版本:
-Dosgi.requiredJavaVersion=1.6
-Xms1600m
-Xmx1600m
-XX:NewSize=800m
-XX:MaxNewSize=800m
-XX:PermSize=256m
-XX:MaxPermSize=256m
-XX:+DisableExplicitGC
-XX:CompileThreshold=100
-Xverify:none
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:=80

❹ java編寫小型的區域網郵件發送

我給你提供一個我在項目裡面實際使用的代碼.
這是我基於一個網上的代碼自己修改封裝過來的.
你可以參考一下
/**
*
*@authorSglee
*
*/
publicclassSimpleMail{

privatestaticStringencode=null;
static{
if("\".equals(File.separator)){
encode="GBK";
}else{
encode="UTF-8";
}
}


/**
*以文本格式發送郵件
*
*@parammailInfo
*@return
*/
(MailInfomailInfo){
for(inti=0;i<3;i++){
//判斷是否需要身份認證
MyAuthenticatorauthenticator=null;
Propertiesproperties=mailInfo.getProperties();
if(mailInfo.isValidate()){
//如果需要身份認證,則創建一個密碼驗證器
authenticator=newMyAuthenticator(mailInfo.getUsername(),
mailInfo.getPassword());
}

//根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
SessionsendMailSession=Session.getDefaultInstance(properties,
authenticator);

if(mailInfo.isDebug()){
sendMailSession.setDebug(true);
}

try{
MessagemailMessage=newMimeMessage(sendMailSession);//根據session創建一個郵件消息

Addressfrom=newInternetAddress(mailInfo.getFromAddress());//創建郵件發送者地址
mailMessage.setFrom(from);//設置郵件消息的發送者

//Addressto=newInternetAddress(mailInfo.getToAddress());//
//創建郵件的接收者地址
//mailMessage.setRecipient(Message.RecipientType.TO,to);//
//設置郵件消息的接收者
mailMessage.setRecipients(Message.RecipientType.TO,
wrapAddress(mailInfo.getToAddress()));

//InternetAddressms=new
//InternetAddress(mailInfo.getMsAddress());
//mailMessage.setRecipient(Message.RecipientType.BCC,ms);//
//密送人
mailMessage.setRecipients(Message.RecipientType.BCC,
wrapAddress(mailInfo.getMsAddress()));

mailMessage.setSubject(mailInfo.getSubject());//設置郵件消息的主題
mailMessage.setSentDate(newDate());//設置郵件消息發送的時間
//mailMessage.setText(mailInfo.getContent());//設置郵件消息的主要內容

//MimeMultipart類是一個容器類,包含MimeBodyPart類型的對象
MultipartmainPart=newMimeMultipart();
MimeBodyPartmessageBodyPart=newMimeBodyPart();//創建一個包含附件內容的MimeBodyPart
//設置HTML內容
messageBodyPart.setContent(mailInfo.getContent(),
"text/html;charset="+encode);
mainPart.addBodyPart(messageBodyPart);

//存在附件
String[]filePaths=mailInfo.getAttachFileNames();
if(filePaths!=null&&filePaths.length>0){
for(StringfilePath:filePaths){
messageBodyPart=newMimeBodyPart();
Filefile=newFile(filePath);
if(file.exists()){//附件存在磁碟中
FileDataSourcefds=newFileDataSource(file);//得到數據源
messageBodyPart
.setDataHandler(newDataHandler(fds));//得到附件本身並至入BodyPart
messageBodyPart.setFileName("=?"+encode+"?B?"
+file.getName());//得到文件名同樣至入BodyPart
mainPart.addBodyPart(messageBodyPart);
}
}
}

//將MimeMultipart對象設置為郵件內容
mailMessage.setContent(mainPart);
Transport.send(mailMessage);//發送郵件
returntrue;
}catch(Exceptione){
e.printStackTrace();
try{
java.util.concurrent.TimeUnit.SECONDS.sleep(5);
}catch(Exceptione2){
e2.printStackTrace();
}
}
}
returnfalse;
}

/**
*將string[]包裝成EmailAddress
*@parammailInfo
*@return
*@throwsAddressException
*/
privatestaticAddress[]wrapAddress(String[]adds)throwsAddressException{
//String[]adds=mailInfo.getToAddress();
if(adds==null||adds.length==0){
returnnull;
}
Address[]to=newAddress[adds.length];
for(inti=0;i<adds.length;i++){
to[i]=newInternetAddress(adds[i]);
}
returnto;
}

/**
*以HTML格式發送郵件
*
*@parammailInfo
*@return
*/
(MailInfomailInfo){
for(inti=0;i<3;i++){

//判斷是否需要身份認證
MyAuthenticatorauthenticator=null;
Propertiesproperties=mailInfo.getProperties();
if(mailInfo.isValidate()){
//如果需要身份認證,則創建一個密碼驗證器
authenticator=newMyAuthenticator(mailInfo.getUsername(),
mailInfo.getPassword());
}

//根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
SessionsendMailSession=Session.getDefaultInstance(properties,
authenticator);

if(mailInfo.isDebug()){
sendMailSession.setDebug(true);
}

try{
MessagemailMessage=newMimeMessage(sendMailSession);//根據session創建一個郵件消息

Addressfrom=newInternetAddress(mailInfo.getFromAddress());//創建郵件發送者地址
mailMessage.setFrom(from);//設置郵件消息的發送者

//Addressto=newInternetAddress(mailInfo.getToAddress());//
//創建郵件的接收者地址
//mailMessage.setRecipient(Message.RecipientType.TO,to);//
//設置郵件消息的接收者
mailMessage.setRecipients(Message.RecipientType.TO,
wrapAddress(mailInfo.getToAddress()));

//InternetAddressms=new
//InternetAddress(mailInfo.getMsAddress());
//mailMessage.setRecipient(Message.RecipientType.BCC,ms);//
//密送人
mailMessage.setRecipients(Message.RecipientType.BCC,
wrapAddress(mailInfo.getMsAddress()));

mailMessage.setSubject(mailInfo.getSubject());//設置郵件消息的主題
mailMessage.setSentDate(newDate());//設置郵件消息發送的時間

//MimeMultipart類是一個容器類,包含MimeBodyPart類型的對象
MultipartmainPart=newMimeMultipart();
MimeBodyPartmessageBodyPart=newMimeBodyPart();//創建一個包含HTML內容的MimeBodyPart
//設置HTML內容
messageBodyPart.setContent(mailInfo.getContent(),
"text/html;charset="+encode);
mainPart.addBodyPart(messageBodyPart);

//存在附件
String[]filePaths=mailInfo.getAttachFileNames();
if(filePaths!=null&&filePaths.length>0){
sun.misc.BASE64Encoderenc=newsun.misc.BASE64Encoder();
for(StringfilePath:filePaths){
messageBodyPart=newMimeBodyPart();
Filefile=newFile(filePath);
if(file.exists()){//附件存在磁碟中
FileDataSourcefds=newFileDataSource(file);//得到數據源
messageBodyPart
.setDataHandler(newDataHandler(fds));//得到附件本身並至入BodyPart
messageBodyPart.setFileName("=?"+encode+"?B?"
+enc.encode(EmailFileNameConvert.changeFileName(file.getName()).getBytes())
+"?=");//得到文件名同樣至入BodyPart
mainPart.addBodyPart(messageBodyPart);
}
}
}

//將MimeMultipart對象設置為郵件內容
mailMessage.setContent(mainPart);
Transport.send(mailMessage);//發送郵件
returntrue;
}catch(Exceptione){
e.printStackTrace();
try{
java.util.concurrent.TimeUnit.SECONDS.sleep(5);
}catch(Exceptione2){
e2.printStackTrace();
}
}

}
returnfalse;
}

}/**
*封裝郵件的基本信息
*
*@authorSglee
*
*/
{
/**
*
*/
=-3937199642590071261L;
privateStringmailServerHost;//伺服器ip
privateStringmailServerPort;//埠
privatelongtimeout;//超時時間
privateStringfromAddress;//發送者的郵件地址
privateString[]toAddress;//郵件接收者地址
privateString[]msAddress;//密送地址
privateStringusername;//登錄郵件發送伺服器的用戶名
privateStringpassword;//登錄郵件發送伺服器的密碼
privatebooleanvalidate=false;//是否需要身份驗證
privateStringsubject;//郵件主題
privateStringcontent;//郵件內容
privateString[]attachFileNames;//附件的文件地址
privatebooleandebug;//調試模式

publicPropertiesgetProperties(){
Propertiesp=newProperties();
p.put("mail.smtp.host",this.mailServerHost);
p.put("mail.smtp.port",this.mailServerPort);
p.put("mail.smtp.auth",validate?"true":"false");
p.put("mail.smtp.timeout",this.timeout);
returnp;
}

publicStringgetMailServerHost(){
returnmailServerHost;
}

publicvoidsetMailServerHost(StringmailServerHost){
this.mailServerHost=mailServerHost;
}

publicStringgetMailServerPort(){
returnmailServerPort;
}

publicvoidsetMailServerPort(StringmailServerPort){
this.mailServerPort=mailServerPort;
}

publicStringgetFromAddress(){
returnfromAddress;
}

publicvoidsetFromAddress(StringfromAddress){
this.fromAddress=fromAddress;
}

publicString[]getToAddress(){
returntoAddress;
}

publicvoidsetToAddress(String[]toAddress){
this.toAddress=toAddress;
}

publicStringgetUsername(){
returnusername;
}

publicvoidsetUsername(Stringusername){
this.username=username;
}

publicStringgetPassword(){
returnpassword;
}

publicvoidsetPassword(Stringpassword){
this.password=password;
}

publicbooleanisValidate(){
returnvalidate;
}

publicvoidsetValidate(booleanvalidate){
this.validate=validate;
}

publicStringgetSubject(){
returnsubject;
}

publicvoidsetSubject(Stringsubject){
this.subject=subject;
}

publicStringgetContent(){
returncontent;
}

publicvoidsetContent(Stringcontent){
this.content=content;
}

publicString[]getAttachFileNames(){
returnattachFileNames;
}

publicvoidsetAttachFileNames(String[]attachFileNames){
this.attachFileNames=attachFileNames;
}

publicvoidsetMsAddress(String[]msAddress){
this.msAddress=msAddress;
}

publicString[]getMsAddress(){
returnmsAddress;
}

publicvoidsetDebug(booleandebug){
this.debug=debug;
}

publicbooleanisDebug(){
returndebug;
}

publicvoidsetTimeout(longtimeout){
this.timeout=timeout;
}

publiclonggetTimeout(){
returntimeout;
}

}{
privateStringusername=null;
privateStringpassword=null;

publicMyAuthenticator(){
};

publicMyAuthenticator(Stringusername,Stringpassword){
this.username=username;
this.password=password;
}

(){
(username,password);
}
}

注意一下:
Myeclipse自帶的JavaEE5.jar和javamail會發生沖突
找到ME下的javeee包
D:MyEclipse8.5Commonpluginscom.genuitec.eclipse.j2eedt.core_8.5.0._5javaee.jar

用rar等解壓工具解開javaee.jar,刪除裡面的javaxmail文件夾(可以先備份javaee.jar)

也即,以後都不能使用javaee.jar裡面的郵件api發送郵件了.

閱讀全文

與javacommonvalidate相關的資料

熱點內容
愛思助手刷機教程數據怎麼恢復 瀏覽:492
iphone6s台積電s8000 瀏覽:207
excel文件圖標異常 瀏覽:576
手機樣機製作教程 瀏覽:747
計算機編程中哪些東西不會變 瀏覽:96
小雞模擬器歷史版本13 瀏覽:102
hi吧網路電話 瀏覽:733
蘋果7鬧鍾鈴聲在哪設置 瀏覽:244
ps文件預覽操作方式 瀏覽:662
qq空間app怎麼換賬號密碼 瀏覽:463
文件夾覆蓋恢復 瀏覽:118
怎麼查看wifi的密碼是多少 瀏覽:211
原始傳奇新區升級套路 瀏覽:701
win10無線網路怎麼連接 瀏覽:251
蘋果解析文件失敗發空間 瀏覽:72
電腦c盤滿了怎麼找到大文件 瀏覽:237
怎麼看網路監控 瀏覽:162
win7開始程序沒有啟動項 瀏覽:125
javacommonvalidate 瀏覽:645
夏普402升級版 瀏覽:223

友情鏈接