1

I know that at stackoverflow are some topic about static content in Spring Web-Application, but after reading 5 of it and a lots of trying, i still can't saw my content of the page. I think that I have correct path on my jsp file. My project structure seams like below:

My project structure

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html; charset=ISO-8859-1"%>

<!DOCTYPE HTML>
<html>
<head>

<link rel="stylesheet" type="text/css" href="<c:url value = '/css/stylesheet.css' />" />
<script type="text/javascript" src="<c:url value = '/js/restful.js' />"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Snore-O-Meter</title>
</head>
<body>
<a href="javascript:HelloWorld()">Hello</a>
</body>
</html>

But I think that is something in default values of web.xml or mvc-dispatcher-servlet.xml:

web.xml

<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Spring MVC Application</display-name>

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="com.springapp.mvc"/>

<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

</beans>

Thank You for any help, I know that is my ignorance of topic, but I had 2 books about Spring and I can't find any useful information about this topic, and I really need working real application to learn spring and creation web-application.

1 Answer 1

2

Put your all your resource folders (css, js, fonts, images, etc.) under a common resources folder. Then add a resource handler

<mvc:resources mapping="/resources/**" location="/resources/" />

You can then change your mapping to, for example

<script type="text/javascript" src="<c:url value = '/resources/js/restful.js' />"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.