action private boolean success;@JSON
public boolean isSuccess(boolean success){
return this.success=success
}@Override
public String execute() throws Exception {
//上传文件代码
isSuccess(false);
return SUCCESS;
}struts.xml<package name="struts-json" extends="json-default" namespace="/">
<action name="upload" class="ty.dfk8.struts.UpLoadAction">
<param name="savefilepath">/upload</param>
<result name="success" type="json">file/uploadfile.jsp</result>
</action>
</package>
jsp页面要怎么显示JSON传回来的值当上传成功时 提示我下载upload.action   用记事本打开里面是{"success":false}}
这是啥缘故 

解决方案 »

  1.   

    jsp页面要怎么显示JSON传回来的值 什么意思??
    你有用到JSON块吗?public class UpAction extends ActionSupport {
    String name;
    File photo; // JSP页面上传文件name属性值
    String photoFileName;// 系统内定自动获取文件名
    String photoContentType; // 上传文件类型
    String path; // 配置文件内配置 public String getPath() {
    return path;
    } public void setPath(String path) {
    this.path = path;
    } public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } public File getPhoto() {
    return photo;
    } public void setPhoto(File photo) {
    this.photo = photo;
    } public String up() {
    System.out.println("OK");
    System.out.println(name);
    System.out.println(photoContentType);
    try {
    FileOutputStream fos = new FileOutputStream(path + "\\"
    + photoFileName);
    FileInputStream fis = new FileInputStream(photo);
    byte[] buffer = new byte[1024 * 10];
    int count = 0;
    while ((count = fis.read(buffer)) > 0) {
    fos.write(buffer, 0, count);
    }
    fos.close();
    fis.close();
    ServletActionContext.getRequest().getSession().setAttribute(
    "result", "photo/" + photoFileName);
    System.out.println("success!!");
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } return "result";
    } public String getPhotoFileName() {
    return photoFileName;
    } public void setPhotoFileName(String photoFileName) {
    this.photoFileName = photoFileName;
    } public String getPhotoContentType() {
    return photoContentType;
    } public void setPhotoContentType(String photoContentType) {
    this.photoContentType = photoContentType;
    }
    }这是一个Struts2.0上传的例子不知有没有用你看看吧,我有点不知道你说的什么!!
      

  2.   

    HttpServletResponse response = this.getResponse();
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html");在你的返回方法中加上面这个
      

  3.   

    在xml里相应的package的extends="json-default" 就可以了。然后让你的action返回到页面里是一个json形式的字符串就ok了~
      

  4.   

    谢谢一楼哈!
    我问的是ajax页面接收返回值  误导你了 给分了