0

I have a maven project.

project structure

my css and js files are under -src -main -webapp -resources ( -css and -js )

My application is deployed successfully but css and js are not getting loaded while opening jsp page on browser ( http://url:8080/test_jboss_local/admin). Getting :

00:44:12,027 INFO [STDOUT] WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/test_jboss_local/resources/css/main.css] in DispatcherServlet with name 'appServlet' 00:44:12,054 INFO [STDOUT] WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/test_jboss_local/resources/js/jquery.1.10.2.min.js] in DispatcherServlet with name 'appServlet' 00:44:12,164 INFO [STDOUT] WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/test_jboss_local/resources/js/main.js] in DispatcherServlet with name 'appServlet' Servlet-context.xml :

<annotation-driven />
       <context:annotation-config />
       <context:component-scan base-package="com.abc" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <beans:property name="prefix" value="/WEB-INF/views/" />
              <beans:property name="suffix" value=".jsp" />
       </beans:bean>

<resources mapping="/admin/**" location="/resources/" />

Security-context.xml :

       <http pattern="/resources/css/*.css" security="none" />
       <http pattern="/resources/js/*.js" security="none" />

       <http auto-config="true">
              <intercept-url pattern="/admin**" access="ROLE_USER" />
       </http>
<authentication-manager>
         <authentication-provider>
           <user-service>
              <user name="vvv" password="123456" authorities="ROLE_USER" />
           </user-service>
         </authentication-provider>
       </authentication-manager>

Web.xml:

<context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>
              /WEB-INF/spring/root-context.xml /WEB-INF/spring/security-context.xml
       </param-value>
       </context-param>

       <servlet>
              <servlet-name>appServlet</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <init-param>
                     <param-name>contextConfigLocation</param-name>
                     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
              <servlet-name>appServlet</servlet-name>
              <url-pattern>/</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
              <servlet-name>appServlet</servlet-name>
              <url-pattern>*.css</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
              <servlet-name>appServlet</servlet-name>
              <url-pattern>*.js</url-pattern>
       </servlet-mapping>
       <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
       <filter>
              <filter-name>springSecurityFilterChain</filter-name>
              <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
       </filter>
       <filter-mapping>
              <filter-name>springSecurityFilterChain</filter-name>
              <url-pattern>/*</url-pattern>
       </filter-mapping>

Root-context.xml:

<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->
       <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
       <context:component-scan base-package="com.abc" />

       <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- <property name="dataSource" ref="dataSource" /> -->
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
    </bean>

Main.css :

h1{
       color:red;
}

Main.js :

jQuery(document).ready(function($) {

       $('#msg').html("This is updated by jQuery")

});

Admin.jsp :

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page session="true"%>
<html>
<head>
<link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
<script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"></script>
<script src="<c:url value="/resources/js/main.js" />"></script>
</head>
<body>
       <h1>Title : ${title}</h1>
       <h1>Message : ${message}</h1>
       <div id="msg"></div>

       <c:if test="${pageContext.request.userPrincipal.name != null}">
          <h2>Welcome : ${pageContext.request.userPrincipal.name} 
           | <a href="<c:url value="/j_spring_security_logout" />" > Logout</a></h2>  
       </c:if>


</body>
</html>

HelloCOntroller.java :

@Controller
public class HelloController {

       @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET)
       public ModelAndView welcomePage() {

              ModelAndView model = new ModelAndView();
              model.addObject("title", "Spring Security Hello World");
              model.addObject("message", "This is welcome page!");
              model.setViewName("hello");
              return model;

       }

       @RequestMapping(value = "/admin**", method = RequestMethod.GET)
       public ModelAndView adminPage() {

              ModelAndView model = new ModelAndView();
              model.addObject("title", "Spring Security Hello World");
              model.addObject("message", "This is protected page!");
              model.setViewName("admin");

              return model;

       }

I have searched on net as well but not able to identify the issue. Please help why my css and js are not getting loaded.Why I am getting No mapping found for css and js.

VJS
  • 2,891
  • 7
  • 38
  • 70
  • What is your resource handler mapped to? – Sotirios Delimanolis Sep 02 '14 at 05:43
  • I am new in this.Can you please explain a bit – VJS Sep 02 '14 at 05:44
  • You've declared a resource handler with `` in your `servlet-context.xml`? Why? What path did you map resource to? What path are you using to request them? – Sotirios Delimanolis Sep 02 '14 at 05:45
  • @Sotirios : In servlet-context, I have seen this in tutorial available in net. Where I have to declare it ? My css and js are under resources folder like resources->css->main.css. Can you please suggest what changes are required.May be in or admin.jsp – VJS Sep 02 '14 at 05:50
  • Notice `mapping="/admin/**` but you are sending your request to `.../resources/...`. How is that supposed to work? – Sotirios Delimanolis Sep 02 '14 at 05:51
  • ok..So should I change and try /resources/css/main.css in admin.jsp to /admin/css/main.css ? – VJS Sep 02 '14 at 05:53
  • You could try it, but note your `adminPage()` handler method. I recommend you go read the Spring documentation and learn what you are doing rather than going about it randomly. – Sotirios Delimanolis Sep 02 '14 at 05:55

0 Answers0