如何把Action后台是否执行成功返回到页面中

public void deleteFile(){
  String rst = "error";
  try {
   DisaMedia disaMedia = this.getDisaMediaService().getDisaMediaById(mediaId);
   String path1 =ServletActionContext.getServletContext().getRealPath("/");
   path1 = path1 + disaMedia.getUrl() + disaMedia.getName();
   File file = new File(path1);
   file.delete();
   
   this.getDisaMediaService().deleteDisaMedia(mediaId);
   rst = "success";
  } catch (Exception e) {
   e.printStackTrace();
  }
  this.printOut(rst);
 }

 

 

public void printOut(String str) {

  HttpServletResponse response = this.getResponse();
  try {
   response.setContentType("text/html;CHARSET=utf-8");
   response.setCharacterEncoding("UTF-8");
   response.getWriter().print(str);
  } catch (IOException ioe) {
   ioe.printStackTrace();
  }
 }

 

设置了void就不用在sturts配置文件中配置success\error信息。

在页面中:

$.post('${ctx}/rims/disaMedia/deleteFile.do?mediaId='+mediaId)
       .success(
        function(data) {
         if(data == "success"){
           $.messager.show({title:'操作提示',msg:'删除文件成功!',showType:'show'});
            $('#fileList').remove(this);
         }else{
           $.messager.show({title:'操作提示',msg:'删除文件失败!',showType:'show'});
         }
           }
       ).error(
        function() {
          $.messager.show({title:'操作提示',msg:'删除文件失败!',showType:'show'});
           }
       );

你可能感兴趣的:(exception,function,String,File,action,Path)