Maven web项目HTTP状态[404] - [未找到]

时间:2017-06-12 05:14:29

标签: java maven intellij-idea maven-3

我使用maven-archetype-webapp

启动了具有以下结构的IntellIJ网络项目

enter image description here

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]

enter image description here

我成功清理并构建了Maven项目。我升级到OS 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>

无济于事。

2 个答案:

答案 0 :(得分:2)

要使用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>

答案 1 :(得分:1)

您没有映射到网址:add_action( 'admin_init', 'my_remove_menu_pages' );function my_remove_menu_pages() { global $user_ID; if ( current_user_can( 'author' ) ) { remove_menu_page( 'edit.php' ); remove_menu_page( 'path visible when you hover on the menu' ); remove_menu_page( 'edit.php?post_type=news' ); /*for custom post type*/ }} ,但您已映射到网址:http://<host>/index.jsp

http://<host>/

如果您愿意,也可以将<url-pattern>/</url-pattern> 更改为其他模式。