Tomcat adds [/] to the URL, Struts can't get the correct action name?

大兔子大兔子 提交于 2019-12-06 14:37:15

The Tomcat is adding a trailing slash because you requested a directory. To distinguish a directory from the file with the same name the trailing slash is added by the Tomcat. Other web servers including Jetty also comply to this rule without doubt. Otherwise how would they serve directory browsing and welcome file list. On the other hand Struts' Default Action Mapper parses URL to determine Action Mapping from it. There are also different implementations of the ActionMapper interface that create mapping for your action. The default action mapper uses the last slash to separate the namespace from the action name. There are also configurations where you can see slashes in the action name, if the configuration setting allows this then the namespace is determined after matching the action name. You can easy solve your problem if you rename your action to something other than directory name. Note that convention plugin is adding a trailing slash when handling an unknown action.

Slashes at the end of the URL is a style that you can follow to normalize URL. Struts can handle mapping with the trailing slash and action name "". You can also decide which style is better suited to you by looking at Trailing slash in URLs - which style is preferred.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!