anshiqiangdaqi 2015-02-09 06:32 采纳率: 0%
浏览 1816

action往jsp传值问题(struts2)

jsp中:
function upload(){
if(checkEmpty($("#ip")[0],"IP地址")&&checkEmpty($("#content")[0],"目录")&&checkEmpty($("#uploadFilePath")[0],"上传文件本地路径")){
$.post("gatherMainTainUpload.action",
{"gatherMainTain.ip":document.getElementById("ip").value,
"gatherMainTain.content":document.getElementById("content").value,
"gatherMainTain.uploadFilePath":document.getElementById("uploadFilePath").value
},
function(data){
alert($("#flag").val());
if(data+""=="true"){
if($("#flag").val()=="true"){
alert("上传文件成功!");
}else{
alert("目录不存在,无法上传文件,请重新输入!");
}
}else{
alert("上传文件失败!");
}

                    }

);
}

}

action中:
public String gatherMainTainUpload() throws Exception{
try{

        this.gatherMainTains = this.gatherMainTainBeanRemote.selectByCondition(gatherMainTain);

        GatherMainTainAction sf = new GatherMainTainAction();
        String host = gatherMainTain.getIp();
        int port = Integer.parseInt(gatherMainTains.get(0).getPort());
        String username = gatherMainTains.get(0).getUserName();
        String password = gatherMainTains.get(0).getPassWord();

        String directory = gatherMainTain.getContent();
        String uploadFile = gatherMainTain.getUploadFilePath();

        ChannelSftp sftp=sf.connect(host,port,username,password);

        //判断当前目录是否存在
        this.gatherMainTain.setFlag("false");
        try {
            SftpATTRS sftpATTRS = sftp.lstat(directory);
            if(sftpATTRS.isDir()){
                this.gatherMainTain.setFlag("true");
            }
        } catch (Exception e) {
            if (e.getMessage().toLowerCase().equals("no such file")) {
                this.gatherMainTain.setFlag("false");
            }
        }

// if(gatherMainTain.getFlag()=="true"){
// sftp.cd(directory);
// File file=new File(uploadFile);
//

// //uploadFile是本地文件所在绝对路径名
// sftp.put(new FileInputStream(file), file.getName());
// }
//

    }
    catch(Exception e){
        e.printStackTrace();
        throw(new GatherException(e));
    }
    return SUCCESS;
}


配置文件:
        <action name="gatherMainTainUpload" class="system_gatherMainTainAction"
        method="gatherMainTainUpload">
        <result name="success">/ajaxTrue.jsp</result>
  • 写回答

3条回答

  • anshiqiangdaqi 2015-02-09 06:37
    关注

    action可以正常执行,文件可以上传,我想判断目录是否存在,设置了flag,后台测试没问题,但是怎么传回页面啊,get set方法也都有,求指点菜鸟,谢谢

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样