m0_74217538 2024-07-22 15:04 采纳率: 0%
浏览 6

@RequestMapping无法获取本地端口号

@RequestMapping( "/captcha")无法获取到本地端口号
这个url地址在浏览器打开显示的是

http://localhost/captcha

但我需要的地址是

http://localhost:8080/captcha

@RequestMapping( "/captcha")没有获取到本地端口号接着他下面的代码段无法执行
``

``
@RequestMapping( "/captcha")无法获取到本地端口号
这个url地址在浏览器打开显示的是

http://localhost/captcha

但我需要的地址是

http://localhost:8080/captcha

``

 @RequestMapping( "/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("11111111111111111111111");
        response.setHeader("Cache-Control", "no-store, no-cache");
        response.setContentType("image/jpeg");
        SpecCaptcha captcha=new SpecCaptcha(200,33,4);
        captcha.setCharType(Captcha.TYPE_ONLY_NUMBER);
        CaptchaUtil.out(captcha,request,response);
        System.out.println("222222222222222222222222");
    }

这种问题该怎么处理啊?

这种问题该怎么处理啊?
  • 写回答

6条回答 默认 最新

  • @summer@ 2024-07-23 10:31
    关注

    http://localhost/captcha 这个地址用的端口号其实是80.只不过浏览器的http默认端口就是80,可以不写。也就是http://localhost/captcha=http://localhost:80/captcha

    你可以在application.properties或application.yml文件中设置端口号,例如: server.port=8080 这样就是设置了8080端口

    img

    如果设置了还不生效,那就说明操作系统环境变量中或者Java系统属性(在命令行中使用-D指定)设置过server.port。修改这两个地方即可

    评论

报告相同问题?

问题事件

  • 创建了问题 7月22日