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条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题