会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132600个问题
Python 全系列/第一阶段:Python入门/控制语句 27183楼
Python 全系列/第一阶段:Python入门/控制语句 27184楼

this.size++报错哪里出问题了
/*
* 基于双向链表实现元素存储的容器
* */
public class MyDoublyLinkedList<E> implements MyList<E> {

    /*
    * 定义双向链表的节点对象
    * */
    class Node<E>{
         E item;
         Node<E> prev;      //记录前一个节点对象
         Node<E> next;      // 记录下一个节点对象
         Node(Node<E> prev,E item,Node<E> next){
             this.prev = prev;
             this.item = item;
             this.next = next;
         }
    }
    private  Node head;   //记录头节点
    private  Node tail;   //记录尾节点
    private  Node size;   //记录原元素个数

    /*
    * 向双向链表中添加元素的方法
    * */
    @Override
    public void add(E element) {
        this.linkLast(element);
    }

    /*
    * 将节点对象添加到双向链表尾部
    * */
    private void linkLast(E element){
        //获取尾节点
        Node t = this.tail;
        //创建节点对象
        Node<E> node = new Node<>(t,element,null);
        //将新节点定义为尾节点
        this.tail = node;
        if(t == null){
            this.head = node;
        }else{
            t.next = node;
        }
        this.size++
    }

    /*
    * 根据指定位置获取元素
    * */
    @Override
    public E get(int indxe) {
        return null;
    }

    /*
    * 返回元素个数
    * */
    @Override
    public int size() {
        return 0;
    }

    /*
    * 根据指定位置删除元素*/
    @Override
    public E remove(int index) {
        return null;
    }

    public static void main(String[] args) {

    }
}

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/数据结构 27186楼
Python 全系列/第一阶段:Python入门/控制语句 27187楼
Python 全系列/第一阶段:Python入门/控制语句 27189楼
大数据全系列/第七阶段:Hadoop 分布式计算MapReduce和资源管理Yarn/MapReduce 原理和搭建 27191楼

老师怎么弄都找不到路径

servlet代码

public class downFileServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 相对路径转换为绝对路径
         */
        ServletContext servletContext = this.getServletContext();
        //context.getRealPath("path")
        //该方法可以将一个相对路径转换为绝对路径,在文件上传与下载时需要用到该方法做路径的转换。
        String realPath = servletContext.getRealPath("sj.jpg");
        System.out.println(realPath);

       // resp.setContentType("image/jpg;charset=utf-8");

        //获得文件
        File file = new File(realPath);
        //读取文件
        System.out.println(file.getName()+"  "+file.getPath());
        FileInputStream fis = new FileInputStream("file");
        byte[]buf = new byte[fis.available()];
        //将图片读到数组里
        fis.read(buf);

        //setHeader和addHeader都一样  再响应中添加附加信息
        resp.setHeader("Content-Disposition", "attachment; filename="+file.getName());

        //字节输出流  向客户端浏览器做字节输出
        OutputStream os = resp.getOutputStream();
        os.write(buf);
        os.flush();
        os.close();
        fis.close();
    }
}

image.png


错误信息

image.png


我把图片名字和图片路径都打印了显示正常  

是不是图片没有部署到tomcat的副本中??怎么解


JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 27193楼
Python 全系列/第一阶段:Python入门/控制语句 27194楼
Python 全系列/第一阶段:Python入门/控制语句 27195楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637