Discuss / Java / 有这么几个疑问

有这么几个疑问

Topic source

1、运行后一直404

本来想提问来着,写着写着发现不对,原来我把URI写成URL了= =,留给大家当教训吧

原始代码的log是这样的

18:24:14.914 [http-nio-8080-exec-1] INFO  c.p.l.framework.DispatcherServlet - a request for http://localhost:8080/

下载的示例项目里面我也添加了几条log,显示的是a request for /

检查了一下处理url的那几行,写的和示例项目里是一样的...

后来直接尝试输出req.getRequestURL(),结果提示是StringBuffer无法赋值给String

getRequestURL()的返回值不是string吗,为什么无法赋值啊。。。

如果用logger.info获取getRequestURL()

logger.info(req.getRequestURI());

String path = req.getRequestURL().toString();

logger.info("a request for {}", path);

/signin

 a request for http://localhost:8080/signin

(另,老师您的项目没添加logback依赖,我添加依赖放上配置文件后才输出log)

2、indexservlet里的业务逻辑

设计的是name参数为空时,是显示*"Hello, World!"*

然而示例项目运行后只显示*"Hello, !"*

这个问题我就是真不知道答案了,html和js我都不会。。。难道是多了个“/”的原因?

来人,上log

19:39:55.030 [http-nio-8080-exec-1] INFO com.itranswarp.learnjava.framework.DispatcherServlet - a get request

19:39:55.031 [http-nio-8080-exec-1] INFO com.itranswarp.learnjava.framework.DispatcherServlet - a request for /hello

19:39:55.032 [http-nio-8080-exec-1] INFO com.itranswarp.learnjava.framework.DispatcherServlet - name:

19:39:55.035 [http-nio-8080-exec-1] DEBUG com.mitchellbosecke.pebble.loader.ServletLoader - Looking for template in /WEB-INF/templates//hello.html.

19:39:55.037 [http-nio-8080-exec-1] DEBUG com.mitchellbosecke.pebble.PebbleEngine - Tokenizing template named /hello.html

忘了删地址了= =

请问老师能帮忙删一下吗

🙏谢谢老师


  • 1

Reply