Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use spring:url tag?

Tags:

url

spring

tags

I think the question is the same for huge manipulations with URL (ie Why?). Where people just reconstruct the URL from scratch.

Does it not hinder the visibility of the app for UI developers if all they see:

<link href="${some_url_possibly_not_named_logically_i_e_karamba1243}/less/bootstrap.less"/> 

I just don't understand use cases where these tags are used and why should I? How can this example snippet be improved with usage of spring:url tag? Would it be used just to remove repetitive part of URL?

<div id="header">
            <ul>
                <li><a href="/futfarm/home/">Home</a></li>
                <li><a href="/futfarm/person/myProfile/">My Profile</a></li>


                <sec:authorize access="hasRole('ROLE_Coach')">

                    <li><a href="/futfarm/coach/training/viewbank">Training</a></li>
                </sec:authorize>

                <sec:authorize access="hasRole('ROLE_Player')">

                    <li><a href="/futfarm/player/training/viewbank">Training</a></li>
                </sec:authorize>


                <sec:authorize access="hasRole('ROLE_Manager')">

                    <li><a href="/futfarm/manager/administration">Administration</a></li>
                </sec:authorize>
            </ul>
        </div>

Or the major concern is that if same URL will be used in another .jsp we can just grab a variable, but then again this tag is specific to jsp scope so other pages cannot use it. I What's wrong with the traditional approach? Are there examples where I can't use anything but spring:url.

It is exactly one of those cases where everyone uses it, no one explains(even google - providing super url reconstruction cases) and everyone happy except me, feeling confused and dumb :-)

like image 686
Aubergine Avatar asked Oct 21 '22 02:10

Aubergine


1 Answers

Use it when you need to have dynamic components in generated URLs (e.g. /app/resources/{name}) and when you need to make sure those URL components (e.g. {name} as above) are properly escaped. Look here for more info.

Also note that you CAN have global attributes that you use with e.g. the <spring:url /> tag across multiple JSPs. Have a look at setExposedContextBeanNames(String[]) here.

like image 117
Jukka Avatar answered Nov 15 '22 06:11

Jukka