Tuesday 8 October 2013

How to include external CSS or JavaScript file to the JSP in your Portlet

If you have an external JS or CSS file and want to include that in your JSP, here is a simple way to do that.

<script language="javascript" src='<%=renderRequest.getContextPath() + "/js/sample.js" %>'>
</script>


<link rel="stylesheet" type="text/css" href="<%=renderRequest.getContextPath() + "/css/sample.css" %>">

The CSS file is located at /webapps/css/

The JS file is located at /webapps/js/

And JSP is located at /webapps/WEB-INF/jsp

Hope this helps.

1 comment:

  1. thanks a lot, this is what i was looking for, including that renderRequest.getContextPath()
    Thans again

    ReplyDelete