会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132452个问题

老师,我想追问一下下图的问题,如果还要自己在tomcat的项目文件夹中自己添加image/picture.jpg, 那为什么要在项目文件夹中创建image文件夹?我没在项目中创建image文件夹和图片,还是可以通过/download.do下载文件,如图二。


image.png

image.png

代码:

package com.bjsxt.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

public class DownloadFileServlet 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 servletContext = this.getServletContext();
        // 路径转换
        String realPath = servletContext.getRealPath("image/rickandmortybg.jpg");
        System.out.println(realPath);
        // 读文件
        File file = new File(realPath);
        System.out.println(file.getName());
        FileInputStream fis = new FileInputStream(file);
        byte[] buff = new byte[fis.available()];
        fis.read(buff);

        // 在响应中添加附加信息
        resp.addHeader("Content-Disposition", "attachment;filename=" + new String(file.getName().getBytes("utf-8"), "iso-8859-1"));

        OutputStream os = resp.getOutputStream();
        os.write(buff);
        os.flush();
        os.close();
    }
}


JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 31816楼
人工智能/第十四阶段:深度学习-目标检测YOLO(V8正在更新中)实战/YOLOv1详解 31817楼
Python 全系列/第十五阶段:Python 爬虫开发/爬虫基础 31818楼

pygame
SCRREN_WIDTH=SCRREN_HEIGH=BG_COLOR=pygame.Color()
MainGame():
    Window=():
        ():
        pygame.display.init()
        MainGame.Window=pygame.display.set_mode([SCRREN_WIDTHSCRREN_HEIGH])
        pygame.display.set_caption()
        :
            MainGame.Window.fill(BG_COLOR)
            .getEvent()
            pygame.display.update()
    ():
        ()
        ()   ():
        eventList=pygame.event.get()
        event eventList:
            event.type==pygame.QUIT:
                .endGame()
            event.type==pygame.KEYDOWN:
            event.type==pygame.K_LEFT:
                ()
            event.type==pygame.K_RIGHT:
                ()
            event.type==pygame.K_UP:
                ()
            event.type==pygame.K_DOWN:
                ()
Tank():
    ():
        ():
        ():
        ():
        MyTank(Tank):
    ():
        EnemyTank(Tank):
    ():
        Bullet(): ():
        ():
        ():
        Wall():
    ():
        ():
        Explode():         ():
        ():
        Music():
    ():
        ():
        __name__==:
    MainGame().stratGame()

 亲爱的 老师 您好   我 就是按您的方法   看过一遍  然后一步步确定    然后我运行它第一步   Quit  退出  就不行  没连接上,  包括我随便改bgcolor 参数 它也不会变颜色      老师 我哪里错了  我像请教下     也让我明白 该怎么做怎么改  谢谢

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 31819楼

一、贴吧项目部署出现问题描述:错误日志截图如下


2019-05-27 14:39:35,018:运行WSGI应用程序时出错
2019-05-2714:39:35,029:ValueError:时区设置不正确:亚洲/上海
2019-05-27 14:39:35,030:文件“/var/www/mengbo_pythonanywhere_com_wsgi.py”,第89行,在<module>中
2019-05-27 14:39:35,030:application = get_wsgi_application()
2019-05-27 14:39:35,030:在get_wsgi_application中输入“/home/mengbo/blogenv/local/lib/python2.7/site-packages/django/core/wsgi.py”,第13行
2019-05-27 14:39:35,030:django.setup(set_prefix = False)
2019-05-27 14:39:35,031:文件“/home/mengbo/blogenv/local/lib/python2.7/site-packages/django/__init__.py”,第22行,在设置中
2019-05-27 14:39:35,031:configure_logging(settings.LOGGING_CONFIG,settings.LOGGING)
2019-05-27 14:39:35,031:在__getattr__中输入“/home/mengbo/blogenv/local/lib/python2.7/site-packages/django/conf/__init__.py”,第56行
2019-05-27 14:39:35,031:self._setup(name)
2019-05-27 14:39:35,031:文件“/home/mengbo/blogenv/local/lib/python2.7/site-packages/django/conf/__init__.py”,第41行,在_setup2019-05-27
14:39:35,031:self._wrapped =设置(settings_module)
2019-05-27 14:39:35,032:在__init__中输入“/home/mengbo/blogenv/local/lib/python2.7/site-packages/django/conf/__init__.py”,第137行2019-05-27 14:39:35,032:引发ValueError(“时区设置不正确:%s”%self.TIME_ZONE)
2019-05-27 14:39:35,032:************************************* ************
2019-05-27 14:39:35,032:如果您看到导入错误但不知道原因,
2019-05-27 14:39:35,032:我们有专门的帮助页面来帮助您调试:
2019-05-27 14:39:35,032:https://help.pythonanywhere.com/pages/DebuggingImportError/
2019-05-27 14:39:35,033:************************************* ************

二、已经修改了失去设置如下:

blob.png

部署的项目还是提示上面的失去设置不正确。

老师如何正确配置啊?

Python 全系列/第九阶段:Python_Django2 框架(隐藏)/Django项目阶段-博客项目 31822楼
JAVA 全系列/第十阶段:百战旅游网项目/百战旅游网 31823楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 31824楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 31826楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 31827楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图高级 31829楼
Python 全系列/第六阶段:生产环境部署与协同开发/Git 31830楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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