Case Sensitive URL

拜拜、爱过 提交于 2019-11-30 18:11:18

问题


I've launched a small website.

I have found that I'm getting errors by users and upon investigation see that the urls they are trying to use are all lowercase whereas I've declared them as camelCase.

I've no idea why these users should be trying to use all lower case (I can't imagine anyone would actually take the time to change:

www.mysite.com/myAction.do

to

www.mysite.com/myaction.do

However I can't think of anyway this would otherwise be changed. Has anyone else experienced this where:

yourAction.do in your mapping file is then attempted to be accessed by users as youraction.do ?

I'm using Struts2.3.1, sitemesh 2.4.2 - I've never heard of or encountered such a situation and would like advice on what may be causing it if any of you have encountered the same or similar.

Are there any browsers out there that remap camelCase.do to camelcase.do ? For whatever reason.

The only 'solution' I can think of (the best out of two very ugly and inelegant workarounds) is to duplicate the action mappings in struts.xml

<action name="myAction" class="myActionClass" />
<action name="myaction" class="myActionClass" /> //added extra but what a 'dumb' solution

Edit:

Is is possible to do the same with methods?

So that:

myAction!clear.do

will still be correctly mapped with the URL:

myaction!clEAr.do 

?

I notice from re-reading my error logs that it's the 'wrong case' method in the ULR which is causing most errors.


回答1:


You can use regex pattern matcher with (?i) to "embed" the matching flag(s) in the regex body. For example

<constant name="struts.patternMatcher" value="regex" />

<action name="{(?i)myaction}" class="myActionClass" /> 


来源:https://stackoverflow.com/questions/35824661/case-sensitive-url

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