【问题标题】:Not Found Problem (The requested resource [/CustomerManager/] is not available)未找到问题(请求的资源 [/CustomerManager/] 不可用)
【发布时间】:2020-10-01 16:22:54
【问题描述】:

我已经交易了很长时间,但我无法显示网页。我已经交易了几个小时,但我无法弄清楚。我不断收到此错误。当您打开 WebContent 但不打印消息时,目录工作。我需要帮助

我的问题;

enter image description here

索引.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Custom Manager</title>
</head>
<body>
    <h1>${message}</h1>
        <h1>asdasdas</h1>

</body>
</html>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.codejava</groupId>
<artifactId>CustomerManager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <spring.version>5.1.5.RELEASE</spring.version>
    <hibernate.version>5.4.1.Final</hibernate.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.1.5.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.20</version>
        <scope>runtime</scope>
    </dependency>


    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


</dependencies>





<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>13</release>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

客户控制器

package net.codejava.customer;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CustomerController {

    @RequestMapping("/")
    public ModelAndView home() {

        ModelAndView mav = new ModelAndView("index");
        mav.addObject("message", "Hello From Spring MVC");
        return mav;
    }
}

WebAppInitializer

package net.codejava.customer.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class WebAppInitializer  implements WebApplicationInitializer{

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {


        AnnotationConfigWebApplicationContext appContext= new AnnotationConfigWebApplicationContext();
        appContext.register(WebMvcConfig.class);


        ServletRegistration.Dynamic dispatcher= servletContext.addServlet(
                "SpringDispatcher", new DispatcherServlet(appContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }

}

WebMvcConfig

package net.codejava.customer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan("net.codejava")
public class WebMvcConfig {

    @Bean(name = "viewResolver")
    public InternalResourceViewResolver getViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }
}

【问题讨论】:

    标签: java spring eclipse spring-mvc


    【解决方案1】:

    快速解决方案: 如果您从 IDE(eclipse 或 intellij)运行,请打开文件 /.settings 文件。查看标签的值:&lt;property name="context-root" value= 取那个值,它是你的 URL 的根元素。 例如:如果是“abc”,那么你可以使用http://localhost:8082/abc/ 如果该值是其他值,请使用该值。

    其他选项是检查您的tomcat服务器下server.xml下的值并查看标签&lt;Context docBase="abc" path="/abc" 获取路径的值并在您的 URL 中使用。例如:http://localhost:8082/abc/

    【讨论】:

    • 我不明白,我该怎么做?我在所有示例中都收到此错误,我无法进行任何项目。
    • 让我知道您运行应用程序的 IDE。
    • 面向企业 Java 开发人员的 Eclipse IDE。版本:2020-03 (4.15.0) 提前感谢您的关注
    • 转到您系统上的项目位置,例如:在 windows 中它可能是 c:\projects\spring-demo。在项目位置下,您将有“.settings”文件,打开它并找到元素:"&lt;property name="context-root" value="。让我知道价值是什么。这是一回事。另一个是:在eclipse中你的服务器(我假设它是tomcat)文件夹下,打开server.xml并转到&lt;Context docBase="abc" path="/abc"行。向我们展示那条线。
    • org.eclipse.wst.common.component 在这个文件夹中
    【解决方案2】:

    我解决了:右键CustomerManager文件夹-属性-Java构建路径-库-JRE系统库[JavaSe-13]-编辑-将JavaSe-13更改为JavaSe-9-完成-应用。

    项目正在运行。但是为什么不工作 JavaSe 13

    【讨论】:

      猜你喜欢
      • 2014-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多