Reputation: 69
I am using Spring tool suite and I created MVC application. Now I'd like to move to ExtJs with this concept.
But I am not able to include extJs files into JSP.
My servlet looks like this:
<mvc:resources mapping="/resources/**" location="/resources/" />
<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>
<context:component-scan base-package="net.codejava.spingextjs" />
my JSP looks like this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<link href="resources/css/ext-all.css" rel="stylesheet">
<script src="extjs/ext-debug.js" type="text/javascript"></script>
<script src="app/app.js" type="text/javascript"></script>
</head>
<body>
</body>
Folder tree looks like this:
However page won't load and firelogger says that /extjs/ext-debug.js and app/app.js is not located on server (404 on these files). I use tomcat and trying it on localhost.
So my question is, what should I do to import ExtJs in JSP, or should I change home.jsp to home.html (tried this, didn't helped)?
I already made the ExtJs app using static web page and loading in html, however I am not able to force server to load ExtJs using MVC concept.
Upvotes: 0
Views: 2594
Reputation: 1423
You may need to MOVE extjs/ext-debug.js and app/app.js into the resources directory because the other locations will be handled by a dispatcher servlet.
OR, if you do not want to move these files, then add two line in your servlet configuration.
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/extjs/**" location="/extjs/" />
<mvc:resources mapping="/app/**" location="/app/" />
<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>
<context:component-scan base-package="net.codejava.spingextjs" />
If it does not solve the problem after you have moved or added two lines in the configuration file, then try the jstl c:url tag like below.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<link href="<c:url value='/resources/css/ext-all.css' />" rel="stylesheet">
<script src="<c:url value='/extjs/ext-debug.js' />" type="text/javascript"></script>
<script src="<c:url value='/resources/css/ext-all.css' />app/app.js" type="text/javascript"></script>
</head>
<body>
</body>
Upvotes: 0
Reputation: 42306
Your js/css/images need to be located in the resources
folder.
There are a bunch of examples of using ExtJS with Spring MVC out there:
https://github.com/loiane/extjs-crud-grid
It relies on an older version of Ext but it's a nice boilerplate.
Cheers
Upvotes: 0