关于undertown将路径自动rewrite成带斜杠形式的问题

Starting JFinal 4.3 -> http://0.0.0.0:9999

Info: jfinal-undertow 1.7, undertow 2.0.22.Final, jvm 1.8.0_91


2019-08-06 20:58:35

[DEBUG]-[Thread: main]-[io.undertow.server.handlers.resource.PathResourceManager.<clinit>()]: Logging Provider: org.jboss.logging.Log4jLoggerProvider


2019-08-06 20:58:35

[DEBUG]-[Thread: main]-[org.jboss.logging.DelegatingBasicLogger.debugf()]: Setting default session timeout to 1800


2019-08-06 20:58:35

[DEBUG]-[Thread: main]-[io.undertow.server.session.InMemorySessionManager.registerSessionListener()]: Registered session listener io.undertow.servlet.core.SessionListenerBridge@55a1c291


2019-08-06 20:58:37

[INFO]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: {dataSource-1} inited


2019-08-06 20:58:37

[DEBUG]-[Thread: main]-[io.undertow.Undertow.start()]: starting undertow server io.undertow.Undertow@58be6e8


2019-08-06 20:58:37

[INFO]-[Thread: main]-[org.xnio.Xnio.<clinit>()]: XNIO version 3.3.8.Final


2019-08-06 20:58:37

[INFO]-[Thread: main]-[org.xnio.nio.NioXnio.<clinit>()]: XNIO NIO Implementation Version 3.3.8.Final


2019-08-06 20:58:37

[DEBUG]-[Thread: XNIO-1 I/O-2]-[org.xnio.nio.WorkerThread.run()]: Started channel thread 'XNIO-1 I/O-2', selector sun.nio.ch.WindowsSelectorImpl@37201494


2019-08-06 20:58:37

[DEBUG]-[Thread: XNIO-1 I/O-1]-[org.xnio.nio.WorkerThread.run()]: Started channel thread 'XNIO-1 I/O-1', selector sun.nio.ch.WindowsSelectorImpl@5b4b64dc


2019-08-06 20:58:37

[DEBUG]-[Thread: XNIO-1 I/O-3]-[org.xnio.nio.WorkerThread.run()]: Started channel thread 'XNIO-1 I/O-3', selector sun.nio.ch.WindowsSelectorImpl@3ff2548a


2019-08-06 20:58:37

[DEBUG]-[Thread: XNIO-1 I/O-4]-[org.xnio.nio.WorkerThread.run()]: Started channel thread 'XNIO-1 I/O-4', selector sun.nio.ch.WindowsSelectorImpl@77a179d2


2019-08-06 20:58:37

[DEBUG]-[Thread: main]-[io.undertow.Undertow.start()]: Configuring listener with protocol HTTP for interface 0.0.0.0 and port 9999


2019-08-06 20:58:37

[DEBUG]-[Thread: XNIO-1 Accept]-[org.xnio.nio.WorkerThread.run()]: Started channel thread 'XNIO-1 Accept', selector sun.nio.ch.WindowsSelectorImpl@43a32c4c

Starting Complete in 2.4 seconds. Welcome To The JFinal World (^_^)



2019-08-06 20:58:38

[DEBUG]-[Thread: XNIO-1 I/O-4]-[io.undertow.util.PathMatcher.match()]: Matched default handler path /login


2019-08-06 20:58:38

[DEBUG]-[Thread: XNIO-1 I/O-4]-[io.undertow.util.PathMatcher.match()]: Matched default handler path /login/


2019-08-06 20:58:38

[DEBUG]-[Thread: XNIO-1 task-1]-[io.undertow.security.impl.SecurityContextImpl.authenticate()]: Attempting to authenticate /login/, authentication required: false


2019-08-06 20:58:38

[DEBUG]-[Thread: XNIO-1 task-1]-[io.undertow.security.impl.SecurityContextImpl$AuthAttempter.transition()]: Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@3f79c438 for /login/


2019-08-06 20:58:38

[DEBUG]-[Thread: XNIO-1 task-1]-[io.undertow.security.impl.SecurityContextImpl.authTransition()]: Authentication result was ATTEMPTED for /login/


2019-08-06 20:58:38

[WARN]-[Thread: XNIO-1 task-1]-[com.jfinal.core.ActionHandler.handle()]: 404 Action Not Found: /login/


如上,已把控制器路由、拦截器全部注释掉了,还是会出现,当访问login的时候自动302到login/,访问其他名称的路径不会出现这个问题。

评论区

JFinal

2019-08-06 21:08

这个问题与 tomcat 问题是一样的,用一下这篇文件中我给的方法解决:
https://www.oschina.net/question/941098_93842

记得搞定后回来反馈一下

Relyn

2019-08-06 21:34

找到问题了,原来是undertow会自动扫描webapp下面的目录,我刚好有一个名叫login的目录,给LoginController用的,我把这个目录删除后,就不会出现这种自动加斜杠的情况了

JFinal

2019-08-06 21:58

@Relyn 其实就是我上面说的问题,所有模板都放到 webapp/_view 之下可以省很多事,而且统一

多参考 jfinal club 项目

Relyn

2019-08-07 10:51

@JFinal 谢谢,已把工程中所有的前端页面都丢到_view目录下了,完美解决!!

JFinal

2019-08-07 11:17

@Relyn 将所有前端页面丢到 _view 里头去以后,代码并不需要改多少,java 代码这一头在 Routes 添加一行代码:
setBaseViewPath("/_view");

参考 jfinal club 项目中的 FrontRoutes

页面之中要改的就是 #include、#render 指令的模板路径, 当然这个不是必须要改,因为没有路径时默认就是当前路径,例如下面是无路径用法:
#include("_layout.html")

还可以使用相对路径,例如:
#include("abc/def/_layout.html")
以及向上路径表示法:
#include("../common/_layout.html")

总之,java 侧只动 Routes 添加 setBaseViewPath("/_view"),后端在使用绝对路径时只动 #include、#render

最后,建议所有 web 静态资源全放在 webapp/assets 目录下面,同样是参考 jfinal club

热门反馈

扫码入社