0

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.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Sudhakar Krishnan
  • 732
  • 1
  • 8
  • 27
  • 1
    why not just delete the style tag from the stylesheet jsp? – soulcheck Jan 09 '13 at 17:20
  • i'm using ide, so if i remove style tag, my ide wont work properly. – Sudhakar Krishnan Jan 09 '13 at 17:47
  • what do you mean by 'wont work properly'? What you're trying to do now is using a hammer where you should use a skrewdriver (and a small one at that). – soulcheck Jan 09 '13 at 17:49
  • @soulcheck: this is an existing project. There are many css developers working only in css codes. My project is a big one it contains thousands of css generating - jsp pages. In this situation i'm trying to do the easiest approach. If i have to delete i need to delete in all 1000 pages. And this will cause pain in all css developers head. In some pages there are more than ten style tag(due to css developers). This is my challenge. Please help me. – Sudhakar Krishnan Jan 09 '13 at 18:16
  • @soulcheck : deleting the style tag in my jsp (i allready done this - in above code). The problem is for background image (css) = url('/img1.jpg'). With my process ' is creating problem. – Sudhakar Krishnan Jan 10 '13 at 11:59
  • **i'm dynamically generating css and js using jsp/jstl/spring. How to place this result in link tag at head section. not in script tag in head section.** – Sudhakar Krishnan Jan 10 '13 at 12:50

1 Answers1

0

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.

Sudhakar Krishnan
  • 732
  • 1
  • 8
  • 27