当我不发送文件时,如何替换尝试捕获量以不获取错误例外?
我将变量从Ajax发送到Java!在我的AJAX方法中,我发送了2个变量:iDtabprest
和idpolice
! 我会得到错误例外,因为我没有传递文件!即使我不发送文件,我如何才能使此函数起作用并读取变量。 我评论了文件传递变量的尝试/捕获!但是在某些AJAX方法中,我正在使用该文件。
public String upload_via_ajax() {
try {
String property = "java.io.tmpdir";
String tempDir = System.getProperty(property);
String html = "inside upload via ajax";
// try {
// File destFile = new File(tempDir, myFileFileName.substring(0,
// myFileFileName.lastIndexOf(".")) + ".csv");
// FileUtils.copyFile(myFile, destFile);
//
// getRequest().getSession().setAttribute("filePath",
// destFile.getPath());
//POUR REFERENCE DECLARATION
if(annee != null) {
TableReferentielDto tableReferentielDto = new TableReferentielDto();
tableReferentielDto.setId(Long.parseLong(annee));
TableReferentielDto anneeLabel =(TableReferentielDto) tableReferentielGetByIdCmd
.execute(tableReferentielDto);
getRequest().getSession().setAttribute("annee",
anneeLabel.getLibelle());
}
//POUR DATE DEBUT DECLARATION
if(moisDebutDeclaration != null){
getRequest().getSession().setAttribute("moisDebutDeclaration",
moisDebutDeclaration);
}
//POUR DATE FIN DECLARATION
if(moisFinDeclaration != null){
getRequest().getSession().setAttribute("moisFinDeclaration",
moisFinDeclaration);
}
//ID POLICE
if(idPolice != null){
getRequest().getSession().setAttribute("idPolice",
idPolice);
}
if(idTabPrest != null) {
getRequest().getSession().setAttribute("idTabPrest",
idTabPrest);
}
if(idTabTarif != null){
getRequest().getSession().setAttribute("idTabTarif",
idTabTarif);
}
html = "file uploaded";
// } catch (IOException e) {
//
// html = "error in uploading file";
// e.printStackTrace();
// }
return SUCCESS;
} catch (Exception e) {
return SUCCESS;
}
}
I am sending variables from ajax to java! in my ajax method I am sending 2 variables: idtabPrest
and idPolice
!
I am getting an error exception because I am not passing the File ! how can I make this function work and read the variables even if i am not sending the File.
I commented the Try/catch of the file to pass the variables! but in some ajax methods I am using the file.
public String upload_via_ajax() {
try {
String property = "java.io.tmpdir";
String tempDir = System.getProperty(property);
String html = "inside upload via ajax";
// try {
// File destFile = new File(tempDir, myFileFileName.substring(0,
// myFileFileName.lastIndexOf(".")) + ".csv");
// FileUtils.copyFile(myFile, destFile);
//
// getRequest().getSession().setAttribute("filePath",
// destFile.getPath());
//POUR REFERENCE DECLARATION
if(annee != null) {
TableReferentielDto tableReferentielDto = new TableReferentielDto();
tableReferentielDto.setId(Long.parseLong(annee));
TableReferentielDto anneeLabel =(TableReferentielDto) tableReferentielGetByIdCmd
.execute(tableReferentielDto);
getRequest().getSession().setAttribute("annee",
anneeLabel.getLibelle());
}
//POUR DATE DEBUT DECLARATION
if(moisDebutDeclaration != null){
getRequest().getSession().setAttribute("moisDebutDeclaration",
moisDebutDeclaration);
}
//POUR DATE FIN DECLARATION
if(moisFinDeclaration != null){
getRequest().getSession().setAttribute("moisFinDeclaration",
moisFinDeclaration);
}
//ID POLICE
if(idPolice != null){
getRequest().getSession().setAttribute("idPolice",
idPolice);
}
if(idTabPrest != null) {
getRequest().getSession().setAttribute("idTabPrest",
idTabPrest);
}
if(idTabTarif != null){
getRequest().getSession().setAttribute("idTabTarif",
idTabTarif);
}
html = "file uploaded";
// } catch (IOException e) {
//
// html = "error in uploading file";
// e.printStackTrace();
// }
return SUCCESS;
} catch (Exception e) {
return SUCCESS;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论