I don't know how to handle all requests in struts2 (including dots and slashes). I tried:
action name="*"
and
action name="*/*"
It is good for requests that contain one slash but not for more than one slash.
Related
Is it possible to apply Struts 2 Internationalization (i18n) for changing language from English to Hindi on whole web pages of website by single click?
If it is possible then how can I resolve this problem?
As mentioned by #RomanC , it is possible to do that, you need to have the i18n interceptor in your package.
After that you need your jsp page submit a form with request_locale in it, or call an action with request_locale in its parameters . For example, if you want to do it with select you can use below:
<s:form id="langselect" action="locale-manager" namespace="/common">
<s:select name="request_locale" headerKey="-1"
headerValue="Language"
list="#{'en_US':'English', 'fa_IR':'فارسی','ar_SA':'العربية','zh_CN':'中国的'}"
onchange="forms['langselect'].submit()" />
</s:form>
You form action needs nothing to do about changing the locale at all, as the interceptor will do all the job for you.
Changing the locale will change all your 20 pages at once, of course as soon as you reload your pages. So if you want to do it with tab you need to reload your new pages (for example with ajax) or reload your total site to get localized jsp from struts.
The framework is internationalized.
You need to add the corresponding to each locale resource bundles for
the localized messages that you display via the struts tags. Use
text tag or getText() to retrieve a message in the UI.
The browser language is passed with the HTTP request and framework
create a locale corresponding to the browser settings. Switching
locale performed via passing a special parameter request_locale to
i18n interceptor that should be on your stack.
You can also configure this interceptor to accept user-defined
parameters.
Normally switching to a locale persist for the session of the user.
So, you don't have to pass a parameter each time on every request, but
this case is also supported if needed. See how could you achieve all
of the above using localization.
We're using Struts 2 in our web application. There are bunch of action mappings defined already, I want to implement a feature where any Urls starting with /buy and not mapped to any of the existing action mappings e.g. /buy/new or buy/old should be redirected to buy/index action. For example if someone is trying to go to /buy/bla1 or /buy/bla2 or buy/bla1/bla2/bla3 should go to buy/index.
Define the following action in your /buy package:
<action name="*">
<result type="redirectAction">index</result>
</action>
Alternatively you can just use:
<default-action-ref name="index" />
But then you will get no redirect. Instead the index page will show under the nonexisting address.
You also need to set the following parameter in your struts.properties:
struts.action.extension = action,,
You can add other extensions to the parameter, but as far as i know there is no wildcard for all extensions. The blank string covers directories like /buy/bla but /buy/bla.x won't be covered and will produce a 404 error unless you add x to the list of extensions.
If this is not good enough you might be better off solving this by using redirect rules in the webserver.
You can use default action reference and provide a JSP success path to it.
If any unmatched action is received then it will call the given action and forward it to the result JSP page.
Requesting a page from IIS (hosts ASP.NET MVC 3 site) with url containing web.config gives 404 error. Urls with app.config have no problem. Local Visual Studio development server has no issues with this type of urls.
1 - What are any other special words other than web.config, being handled this way by IIS?
In request filtering page/hidden segments tab this is the current state:
I guess these are not special words, because IIS handles words like bin, App_code etc without a problem.
Answer: I guess these are the words being handled by IIS this way. So these are the default words I think and this list is configurable (new items can be added to this list).
2 - Are there any quick fixes (like by web.config modification) to handle urls with these special words?
Btw, I am not trying to serve the web.config file. Url format is : www.mysite.com/es/web.config/1
This is part of the IIS configuration under the Request Filtering section:
You can add/remove filters.
However, I do believe this is a really bad idea to remove web.config from it.
http://www.iis.net/configreference/system.webserver/security/requestfiltering
Cause:
As you already shown a snapshot of IIS configuration. These are reserved folder & files in .Net application, so IIS want to preserve those for security.
URLs which contain these strings as returned as 404 response only if these comes in before ? AND exactly between 2 slashes /../ OR at last. Eg: www.example.com/bin/anything.ext OR www.example.com/folder/sub/web.config
IIS match these string anywhere coz, web.config can we at any directory level.
If anything is with those string are there THEN page will be served by IIS. Eg: www.example.com/bin-folder/anthing.ext OR www.example.com/sub/bin.html OR www.example.com/-web.confing/page.aspx are OK.
I recommend to use some other words with these strings OR use at end of URLs with extensions, so that it will not come between two slashes.
Eg: www.example.com/en-web.config/1 OR www.example.com/en/1/web.config.aspx
Even then I have one Tricky Solution:
If you really need these strings exactly without other words in URL THEN I recommend to use URL-ReWrite.. This may not be quick at whole but except 2nd step its quick and handy, coz second step depends on your application.
1- Add this rule in IIS at top level:
regexp match: (/web|^web)\.(config$|config/) //OR as your requirement
re-write to: handler.aspx?url={REQUEST_URI}
<rule name="web-config" stopProcessing="true">
<match url="(/web|^web)\.(config$|config/)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="handler.aspx?url={REQUEST_URI}" appendQueryString="false" />
</rule>
2- In handler.aspx (or in any other language page) check the url GET variable and respond accordingly.Request.QueryString("url")
Do it carefully coz here you are controlling security.
I suggest to include the actual page content to response in handler.aspx or handler.php only rather then redirecting etc.
Before including content verify URL first(by regular expression etc.), and include content hardcoded, do not take any part of URL in to variable and use that variable in response-inclusion-code.
3- After that at last from IIS manager, In a specific website go to request filtering->hidden segment tab and delete the desire string. Eg: web.config. This step can be done by web.config also:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
<hiddenSegments>
<remove segment="web.config" />
</hiddenSegments>
</requestFiltering>
</security>
Now, IIS will serve the page and your handler page will show the output with exact same URL in user browser.
In my JSF web-app, I want to create a URL for the user to bookmark or copy. That part is easy enough, like this:
<h:link value="Permanent Link"
outcome="/showStuff">
<f:param name="recID" value="#{bean.recordID}" />
</h:link>
Although that link has the desired parameter (recID) in it, it also has the windowid parameter generated by the JSF Servlet. Is there any convenient way to generate the URL without the windowid parameter? Or does this make any difference?
(This is with Mojarra)
You can remove the WindowId using a URLRewriteFilter framework such as OCPsoft Rewrite URLRewriteFilter
Doing something like this should be fairly straightforward using a single configuration rule. You can obviously fiddle if this rule is either too strict or too general.
.defineRule()
.when(Direction.isOutbound().and(
URL.matches("{prefix}{windowId}{suffix}")
.where("windowId").matches("windowId=[^&]+")))
.perform(Substitute.with("{prefix}{suffix}"))
Check out the rewrite site. It's pretty easy to set up. http://ocpsoft.org/rewrite/
I want to ask about canonical URL. Lets assume this URL structure:
/category_A/page1
/category_B/page1
/category_C/page1
Simply put, there are multiple URLs that display the same content. But only /category_A/page1 is original(canonical) page. My question is if it have any impact(bad/good/neutral) considering SEO if I will have canonical URL pointing to /category_A/page1 placed in this same page /category_A/page1 ?
The reason for this is, that its much easier to just put canonical URL into head of every page than to trying find out in which page it is not needed (its the same page as canonical one)
just do it
you described the perfect use case for the canonical tag. the canonical tag is a kind of failsafe against wrong URLs (or URLs with unnecessary parameters). so it's good to have it even on the page with the URL the canonical points to.