简体   繁体   English

.html文件 <welcome-file> 加载.jsp文件时引发404错误

[英].html file in <welcome-file> throws 404 error while a .jsp file loads

My web.xml file 我的web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Go Scrapper</display-name>

  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>                                    
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
  </context-param>

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

  <welcome-file-list>
    <welcome-file>new.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

</web-app>

I only use any one of the following when i run the program, when i use new.jsp, i get a page, but when i use index.html i get an error 404, both are in the same directory, (ie) under WebContent/. 当我运行程序时,我只使用以下任何一项,当我使用new.jsp时,我得到一个页面,但是当我使用index.html时,我得到了一个错误404,两者都位于同一目录下(即)网页内容/。

I have entered both here for ur understanding 我在这里输入都是为了您的理解

My dispatcher-servlet.xml 我的dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

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

    <context:component-scan base-package="com.go.controller" />
    <mvc:annotation-driven />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".html" />
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/GoAnalyserDB" />
        <property name="username" value="postgres" />
        <property name="password" value="toor" />
    </bean>

</beans>

hey guys, When the welcome file is a jsp then it loads the page, If i change it to a html, it hits me with a 404 error. 大家好,当欢迎文件为jsp时,它将加载页面,如果我将其更改为html,则会出现404错误。 I have checked with other codes. 我已经检查了其他代码。 everything seems to be correct. 一切似乎都是正确的。 I cant quite get what i have done wrong here. 我不能完全明白我在这里做错了什么。

    i have tried following way and it's work.

    Spring config:

    <resources mapping="/static/**" location="/WEB-INF/static/" />

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



    Controller method:

    @RequestMapping(value = "/", method = RequestMethod.GET)
      public String homePage(ModelMap model, HttpServletRequest servletRequest, HttpServletResponse response) {
        String returnText = "static/html/index";
        return returnText;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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