gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:58:32 25 4
gpt4 key购买 nike

我使用 IntellIJ 启动了一个具有以下结构的 maven-archetype-webapp web 项目,

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>

没有帮助。

最佳答案

要使用 jsp 解析器,您必须像这样定义一个 Controller :

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>

关于java - Maven web 项目 HTTP 状态 [404] – [未找到],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com