简体   繁体   中英

What is wrong with my spring servlet.xml?

This is a test application to develop a javascript library and when I started it the javascript was in the index.jsp view file. I've since split off the javascript to its own js file. I copied from a file I had a few years ago that used scripts and styles but for some reason it's not working. Before I explain what "not working" means, I'll describe my set up:

My folder structure:

src->main
  main->(java, resources, webapp)
    java->(all the java source)
    resources->{empty}
    webapp->(resources, WEB-INF)
      resources->scripts
      scripts->(my javascript file)
      WEB-INF->(views, Test-service.xml, Test-servlet.xml, web.xml)
        views->index.jsp

My test-service.xml has all my beans and I don't think is the problem but can supply it if someone needs to see the code - there's not much in there though, just a DAO class to access the database.

The test-servlet.xml on the other hand is where I think the error is located:

<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        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-4.1.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <context:component-scan base-package="com.fulmer.seth.controller" />

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

    <!-- <mvc:resources mapping="/resources/scripts/**" location="/resources/scripts" /> -->
</beans>

When I uncomment that mvc:resources line, I get a 404 error when I go to localhost:8080/Test but I can go to localhost:8080/Test/resources/scripts/(file).js, no problem - it'll show me the javascript code so I know my war is executing.

There are no logs other than what Spring sets up on its own but if someone can explain where to find them (I'm using Jetty 9 and execute by mvn jetty:run-war), I'll look for the log files.

Any thoughts what is wrong w/ my servlet.xml or otherwise configuration? I can provide whatever is needed if I have it available.

I discovered the solution. I needed <mvc:annotation-driven /> in the servlet.xml file. Once I added that, I was able to access both JSP and the static resources but before then I guess if one doesn't have the mvc:resources , one doesn't need the other mvc tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM