Question

My team had all ready created a project in spring framework and running successfully. Now i decided to make it run even faster.

Existing project: My developers do their best and created dynamically output css pages using jsp.

Existing code:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <jsp:include page="/WEB-INF/common/layout/head.jsp" />
    < jsp:include page="/WEB-INF/common/css/index.jsp" />
</head>

Out put:

<style type="text/css">
    body{background: #ffffff url('<c:url value='/resources/images/logo/logo_small.png'/>') no-repeat scroll center center}
</style>

There is no error in this code or project this is working fine.

What i need is that, my css files need to be loaded by a link tag in header. something like this:

<link rel="stylesheet" href="/mysite/resource/css/sitemap/index.css" type="text/css">

This will speed up by catching in browser.

What i done up to now: I created a url it points to a jsp.

<c:if test="${branch == 'sitemap'}">
    <c:if test="${page == 'index'}">
        <%@include file="/myfile/dynamic/css/layout/index.jsp" %>
    </c:if>
</c:if>

This code may? works, but there is a problem. I need to replace style type start tag and end tag. I done that by, Importing and replacing by this code:

<c:set var="my_css">
    <c:if test="${branch == 'sitemap'}">
        <c:if test="${page == 'index'}">
            <%@include file="/WEB-INF/common/css/index.jsp" %>
        </c:if>
    </c:if>
</c:set>
<c:set var="css" value='${fn:replace(fn:replace(fn:replace(my_css,"<style type=\\\"text/css\\\">", ""),"</style>", ""),"\'", "99999")}'/>
<compress:css enabled="true">
    <c:out value='${css}'/>
</compress:css>

Here 99999 location is causing problem. Actually i need to replace it with & #39;.

The above code works fine and replaces ' with 9999. But after replace with &.. it not working. The & itself again changing to & amp;

Information : Its a completed project. More css will be generated dynamically. All in jsp pages. Goodluck is that each jsp page ouput only css code. Badluck is that it contains script tag at top and bottom. One more bad luck is on url('').

This ' code is doing the problem in fn:replace tag.

Or if you have a better suggestion please let me know.

I think there will be an easy option. Please let me know your suggestions, advice and help.

Was it helpful?

Solution

I achieved this.

I created a new route /resource/css|js , I use internal resource view resolver - (folder).

My link url is moething like /resource/css/qtn/page1.css.

In controller /resources/{type}/{page}.css.

Here i get type and page values and used this in my dynamic jsp page to achieve my result.

For security i checked the url is it comes from my own page or not.

Hint :

While using internal resource view resolver it will throw error when you pass page values directly to resource url because sometimes page url will be /page1/block1 so our controller throws error.

To solve this i passed page values as /resource/css/qtn/page1.css?sub=${page}.

In controller we can easily cath this sub value and send to our dynamic jsp as model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top