簡體   English   中英

Maven web項目HTTP狀態[404] - [未找到]

[英]Maven web project HTTP Status [404] – [Not Found]

我使用IntellIJ創建了一個具有以下結構的maven-archetype-webapp web項目,

在此輸入圖像描述

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>Bitcoin Wallet</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <description></description>
        <display-name>dispatcher</display-name>
        <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>

</web-app>

dispatcher-servlet.xml文件如下所示,

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

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

    <context:component-scan base-package="com.puut.bitcoin.controllers">
    </context:component-scan>

    <mvc:annotation-driven></mvc:annotation-driven>

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

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

到目前為止,項目中沒有Java源文件。 我收到錯誤HTTP Status [404] – [Not Found]

在此輸入圖像描述

我成功地使用Maven清理並構建項目。 我升級到OS SierraOS Sierra中沒有安裝maven 所以,我不得不手動配置它。 Maven相關信息在這里,

$ mvn -version

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T01:39:06+06:00)
Maven home: /Users/Chaklader/apache-maven-3.5.0
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.4", arch: "x86_64", family: "mac"


$ which mvn 

/Users/Chaklader/apache-maven-3.5.0/bin/mvn

我該怎么做才能運行這個項目?

更新

如上所述,改為

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

沒有幫助。

要使用jsp解析器,您必須定義一個這樣的控制器:

package com.puut.bitcoin.controllers;

@Controller
@RequestMapping(value="/")
public class spaController {

  @RequestMapping(method = RequestMethod.GET)
  public String pagIndex(Model model){

     return "index";
  }
}

在web xml中,最好顯式聲明調度程序servlet使用哪個配置文件。

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

您沒有映射到URL: http://<host>/index.jsp ,但您已映射到URL: http://<host>/

<url-pattern>/</url-pattern>

或者,如果您願意,可以將url-pattern更改為其他模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM