0

I know that this question was answered many times on stackoverflow but I can't make it work following the steps on the answers.

First of all what I want is to add some static files (css js img) to my project to access them from html tags.

My project structure is :

https://i.sstatic.net/5bfVu.jpg

My project works just fine before adding the css but I read in the other posts that I shoud add this line to my dispatcher file :

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

But when I add it I can no more deploy and get this error :

GlassFish Server, deploy, null, false

Note :

I changer some thing in the configuration files to remove the .htm extension from the url.

My dispatcher :

<mvc:resources mapping="/**" location="/" />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/">indexController</prop>
        </props>
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<!--
The index controller.
-->
<bean name="indexController"
      class="indexContr"/>

My web.xml file:

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>/</welcome-file>
</welcome-file-list>

Thanks for your help.

1
  • Have you checked the server log for any exceptions? It is strange that deployment is failing. Please check Your_GlassFish_Location\glassfish\domains\domain1\logs\server.log Commented Jul 24, 2015 at 16:12

1 Answer 1

2
  1. You have mapped as resources all namespace that is available for dispatcher servlet. Reduce it from /** to /jsp/website/**

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

  2. I would recommend you not to keep static resource under /jsp/, here should be jsp's =) Use "static" or "resources" in path

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, Second option is the recommended one.
Thanks my problem is solved I can now build my project, I have one more problem now when I try to access an image I get HTTP Status 404 - Not Found.. Any help?

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.