cd86254081 2015-07-03 09:26 采纳率: 100%
浏览 1871
已采纳

ssh图片上传与音乐上传

最近在看一个图片上传的功能,想模仿实现 音乐播放器的后台音乐上传,但是 upLoadPicture()这段代码看的不是很懂,能不能稍微详细点解释一下里面的每句话和实现思想,如果我要做音乐上传的功能思路也和这个一样吗?

@Controller("PictureAction")
@Scope("prototype")
public class PictureAction extends ActionSupport {

private static final long serialVersionUID = 572146812454L;
private File image; // 上传的文件
private String imageFileName; // 文件名称
private String imageContentType; // 文件类型
User user = (User) ActionContext.getContext().getSession().get("user");
private HttpServletResponse response = ServletActionContext.getResponse();
private HttpServletRequest request = ServletActionContext.getRequest();

private List<Picture> picList;

public List<Picture> getPicList() {
    return picList;
}

public void setPicList(List<Picture> picList) {
    this.picList = picList;
}

private String picId;

private String userId;

private String commentPic;

//省略getter和setter

public String uploadPicture() throws IOException {
    String s = UUID.randomUUID().toString();
    String lastName = imageFileName.substring(imageFileName
            .lastIndexOf(".") + 1, imageFileName.length());
    String name = s + "." + lastName;
    username = user.getUsername();
    //获取服务器路径
    String realpath = ServletActionContext.getServletContext().getRealPath(
            "/upload");
    System.out.println("realpath: " + realpath);
    if (image != null) {
        File savefile = new File(new File(realpath), name);
        if (!savefile.getParentFile().exists())
            savefile.getParentFile().mkdirs();
        FileUtils.copyFile(image, savefile);
        String imagePath = "/sDemo/upload/" + name;
        System.out.println("imagePath: " + imagePath);
        Picture picture = new Picture();
        picture.setUserId(user.getId());
        picture.setUserName(user.getUsername());
        picture.setPictureUrl(imagePath);
        ser.insertPicture(picture);
    }
    return "upload";
}
  • 写回答

2条回答

  • 大河行脚 2015-07-03 09:54
    关注

    图片说明

    音乐上传思路是一样的;
    上面的解释你跟着代码再看看,自己再动动手就差不多了。

    如果回答对你有帮助,请采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!