导航:首页 > 编程语言 > 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相关的资料

热点内容
苹果7闹钟铃声在哪设置 浏览:244
ps文件预览操作方式 浏览:662
qq空间app怎么换账号密码 浏览:463
文件夹覆盖恢复 浏览:118
怎么查看wifi的密码是多少 浏览:211
原始传奇新区升级套路 浏览:701
win10无线网络怎么连接 浏览:251
苹果解析文件失败发空间 浏览:72
电脑c盘满了怎么找到大文件 浏览:237
怎么看网络监控 浏览:162
win7开始程序没有启动项 浏览:125
javacommonvalidate 浏览:645
夏普402升级版 浏览:223
photoshop转换点工具 浏览:11
如何从多个文件夹里 浏览:942
套改需要什么文件 浏览:232
微信电脑发送文件 浏览:473
56培训网app 浏览:595
文件找不到了用什么词表达 浏览:353
iphone4s听歌没有声音了 浏览:344

友情链接