增值应用时不workig 在Spring MVC的Web应用程序使用Maven的web.xml

2019-10-19 04:16发布

我创建使用Spring MVC的Web应用程序。

我面临着这样的一个问题,当我不是在web.xml的context-param提供值,则能够索引页显示,但是当我在web.xml的context-param提供值,那么索引页面不显示。

web.xml中: -当没有提供的context-param值

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

    <display-name>Core Web 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>

    <welcome-file-list>
            <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>

当我试图本地主机:8080 / CoreWebApp /我得到的index.jsp

web.xml中: -当我为的context-param提供价值

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

    <display-name>Core Web 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>

    <welcome-file-list>
            <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
    </welcome-file-list>
    <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>
</web-app>

当我试图本地主机:8080 / CoreWebApp /我没有得到的index.jsp。

Please help me to find out the problem.

My Project Structure is as :-
 CoreWebApp
   |_______________ pom.xml
   |
   |_______________ src
   |                 |_____________ main
   |                                 |___________ java
   |                                 |___________ resources
   |                                 |___________ webapp
   |                                                |____ WEB-INF
   |                                                        |_____ applicationContext.xml
   |                                                        |
   |                                                        |_____ mvc-dispatcher-servlet.xml
   |                                                        |
   |                                                        |_____ web.xml
   |                                                        |
   |                                                        |_____ pages
   |                                                                |________ index.jsp
   |
   |______________ target

Answer 1:

检查日志一些例外,并将它们添加到这个问题。 另外弹簧与名称xml配置MVC搜索: "<the name of the dispatcher servlet>+-servlet"尝试重命名applicationContext.xmlmvc-dispatcher-servlet.xml ,改变路径,并相应地。



Answer 2:

你春天的Servlet中是否有“/”,而对于索引页路径映射。



文章来源: Application not workig when adding value to in web.xml in Spring MVC Web Application Using Maven