会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132462个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 12676楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 12677楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 12678楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 12679楼

你好老师,我的这个输入java点击search就会出现下面这个404未找到错误。但是如果我不加后面的search,直接输入/redirect就会进入百度界面。只要加后面的search就错误






image.png

image.png

image.png

package com.bjsxt.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 重定向相应
 * response.sendRedirect(URL地址)重定向响应会在响应头中添加一个Location的key对应的value是给定的URL。客户端浏览器在解析响应头后自动向Location中的URL发送请求。
 */
public class RedirectServlet 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 {
        //进去之后直接会自动请求百度网页并进入
       // resp.sendRedirect("https://www.baidu.com");//请求一个URL


        req.setCharacterEncoding("utf-8");
        //需求:创建一个搜索页面,通过百度搜索引擎完成内容搜索。
        String search = req.getParameter("search");
        //resp.sendRedirect("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=");
        resp.sendRedirect("https://www.baidu.com/s?wd="+search);

    }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

   
    
    
    
    <servlet>
        <servlet-name>redirectServlet</servlet-name>
        <servlet-class>com.bjsxt.servlet.RedirectServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>redirectServlet</servlet-name>
        <url-pattern>/redirect</url-pattern>
    </servlet-mapping>
    
</web-app>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="/redirect" method="post">
        搜索:<input type="text" name="search" /></br>
        <input type="submit" value="Search">
    </form>
</body>
</html>


JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 12681楼

image.png

Python 全系列/第四阶段:函数式编程和核心特性/生成器、迭代器、动态性 12683楼

import pygame
COLOR_BLUE=pygame.Color(0,0,0)
COLOR_red=pygame.Color(255,0,0)
class MainGame():
    window=None
    def __init__(self):
        pass
    #开始游戏方法
    def startGame (self):
    #加载主窗口
       pygame.display.init()
#创建窗口
       MainGame.window=pygame.display.set_mode([700,600])
       pygame.display.set_caption("坦克大战")
       while True:
         MainGame.window.fill(COLOR_BLUE)
         self.eventlist()
         pygame.display.update()
         MainGame.window.blit(self.getTextSurface("剩余敌方坦克数量%d"%6),(5,5))
#结束游戏
    def endGame(self):
        print("谢谢使用,欢迎下次使用")
        exit()
    def eventlist(self):
        enentlist=pygame.event.get()
        for event in enentlist:
            if event.type==pygame.QUIT:
                self.endGame()
            if event.type==pygame.KEYDOWN:
                if event.key==pygame.K_UP:
                    print("按下上键,坦克向上移动")
                if event.key == pygame.K_DOWN:
                    print("按下下键,坦克向下移动")
                if event.key == pygame.K_LEFT:
                    print("按下左键,坦克向左移动")
                if event.key == pygame.K_RIGHT:
                    print("按下右键,坦克向右移动")
    def getTextSurface(self,text):
        pygame.font.init()
        font=pygame.font.SysFont("kaiti",18)
        testSurface=font.render(text,True,COLOR_red)
        return testSurface
MainGame().startGame()
class Tank():
    def __init__(self):

39.png


这要怎么解决

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 12684楼
JAVA 全系列/第四阶段:网页编程和设计/Jquery(旧) 12685楼

#导入模块
import pygame

SCREEN_WIDTH = 700   # 高度700像素
SCREEN_HEIGHT = 500  # 宽度500像素
BG_COLOR = pygame.Color(0, 0, 0)
TEXT_COLOR = pygame.Color(255,0,0)

class MainGame():
    window = None
    my_tank = None
    def __init__(self):
        pass
    # 开始游戏
    def startGame(self):
        # 加载主窗口
        # 初始化窗口
        pygame.display.init()
        # 设置窗口的大小和显示
        # 设置窗口标题
        MainGame.window = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
        # 初始化我方坦克
        MainGame.my_tank = Tank(350, 250)

        # 设置窗口标题
        pygame.display.set_caption('坦克大战1.03,世界末日')
        while True:
            # 给窗口填充颜色
            MainGame.window.fill(BG_COLOR)
            # 获取事件
            self.getEvent()
            # 绘制文字
            MainGame.window.blit(self.gettextsuface('敌方坦克剩余数量%d'%6),(10,10))
            # 调用坦克显示的方法
            MainGame.my_tank.displayTank()
            pygame.display.update()

    # 结束游戏
    def endGame(self):
        print('谢谢使用,欢迎再来')
        exit()
    #左上角文字绘制
    def gettextsuface(self,text):
        # 初始化字体
        pygame.font.init()
        # 获取字体font对象
        font = pygame.font.SysFont('kaiti',18)
        # 绘制文字信息
        textSuface = font.render(text,True,TEXT_COLOR)
        return textSuface
    # 获取事件
    def getEvent(self):
        # 获取所有事件
        eventlist = pygame.event.get()
        # 遍历事件
        for event in eventlist:
            # 判断按下的键是关闭还是按下键盘
            # 如果按下的是退出 关闭窗口
            if event.type == pygame.QUIT:
                self.endGame()
            # 如果按下的是键盘,判断按下的是上,下,左, 右
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    print('按下左键,坦克向左移动')
                elif event.key == pygame.K_RIGHT:
                    print('按下右键,坦克向右移动')
                elif event.key == pygame.K_UP:
                    print('按下上键,坦克向上移动')
                elif event.key == pygame.K_DOWN:
                    print('按下下键,坦克向下移动')
class Tank():
    # 添加距离左边left 距离上边top
    def __init__(self, left, top):
        # 保存加载的图片
        self.images = {
            'U': pygame.image.load('img/p1tankU.gif'),
            'D': pygame.image.load('img/p1tankD.gif'),
            'L': pygame.image.load('img/p1tankL.gif'),
            'R': pygame.image.load('img/p1tankR.gif')
        }
        # 方向
        self.direction = 'U'
        # 根据当前图片的方向获取图片  surface
        self.image = self.images[self.direction]
        # 根据图片获取区域
        self.rect = self.image.get_rect()
        # 设置区域的left和TOP
        self.rect.left = left
        self.rect.top = top

    #移动
    def move(self):
        pass

    #射击
    def shot(self):
        pass

    #展示坦克的方法
    def displayTank(self):
        # 获取展示的对象
        self.image = self.images[self.direction]
        # 调用blit方法展示
        MainGame.window.blit(self.image, self.rect)

# 我方坦克
class MyTank(Tank):
    def __init__(self):
        pass

# 敌方坦克
class EnemyTank(Tank):
    def __init__(self):
        pass

# 子弹类
class Bullet():
    def __init__(self):
        pass

    #展示子弹
    def displayBullet(self):
        pass

    #移动
    def move(self):
        pass

# 墙壁类
class wall():
    def __init__(self):
        pass
    #展示墙壁
    def displaywall(self):
        pass

# 爆炸效果的类
class Explode():
    def __init__(self):
        pass
    #展示爆炸效果的方法
    def displayExplode(self):
        pass

# 音效类
class Music():
    def __init__(self):
        pass

    #播放音乐的方法
    def play(self):
        pass

if __name__=='__main__':
    MainGame().startGame()
    # MainGame().gettextsuface()
    
    
    Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "C:\Users\安德虎\PycharmProjects\gui\tanke01.py", line 179, in <module>
    MainGame().startGame()
  File "C:\Users\安德虎\PycharmProjects\gui\tanke01.py", line 46, in startGame
    MainGame.my_tank = Tank(350, 250)
  File "C:\Users\安德虎\PycharmProjects\gui\tanke01.py", line 99, in __init__
    'u': pygame.image.load('img/p1tankU.gif'),
FileNotFoundError: No file 'img/p1tankU.gif' found in working directory 'C:\Users\安德虎\PycharmProjects\gui'.


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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jQuery/jQuery/jquery-3.6.0.min.js"></script>
    <style>
        *{margin: 0;
        padding: 0;}
        .box1{
            list-style: none;
            width: 500px;
            height: 50px;
            margin: 100px auto;
            background-color: skyblue;

        }
        .box1>li{
            float: left;
            width: 99px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            font-size: 20px;
            border-right: 1px solid red;
        }
        .box2{
            list-style: none;
            background-color: burlywood;
            display: none;

        }
        .box2 li:hover{
            color: red;
        }

    </style>
</head>
<body>
    <ul class="box1">
        <li>
            菜单1
            <ul class="box2">
                <li>1</li>
                <li>4</li>
                <li>3</li>
                <li>呃呃</li>
                <li>3</li>
                <li>2</li>
            </ul>
        </li>
        <li>菜单2
            <ul class="box2">
                <li>1</li>
                <li>4</li>
                <li>3</li>
                <li>fsd</li>
                <li>3</li>
                <li>2</li>
            </ul>

        </li>
        <li>菜单3
            <ul class="box2">
                <li>1</li>
                <li>4</li>
                <li>3</li>
                <li>sda</li>
                <li>3</li>
                <li>2</li>
            </ul>
        </li>
        <li>菜单4
            <ul class="box2">
                <li>1</li>
                <li>4</li>
                <li>3</li>
                <li>sdsa</li>
                <li>3</li>
                <li>2</li>
            </ul>
        </li>
        <li>菜单5
            <ul class="box2">
                <li>1</li>
                <li>4</li>
                <li>3</li>
                <li>sadd</li>
                <li>3</li>
                <li>2</li>
            </ul>
        </li>

       
    </ul>
    <script>
        $('.box1 li').on('mouseenter',function(){
            // console.log(e.target)
            // $('.box2').css('display','block')
            $('this').children('.box2').slideDown(500)
        })
    </script>
   
</body>

老师好 我这里鼠标画上去 怎末他不显示啊 老师帮我看看 问题在哪


Python 全系列/第七阶段:网页编程基础/jQuery应用 12687楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 12688楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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