首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >找不到问题(请求的资源[/CustomerManager/]不可用)

找不到问题(请求的资源[/CustomerManager/]不可用)
EN

Stack Overflow用户
提问于 2020-06-12 06:02:47
回答 2查看 149关注 0票数 0

我已经做了很长一段时间的交易,但我无法显示网页。我已经做了几个小时的交易,但我还是弄不明白。我一直收到这个错误。当您打开WebContent但不打印消息时,目录可以正常工作。我需要帮助

我的问题;

enter image description here

Index.jsp

代码语言:javascript
运行
复制
<%@ 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

代码语言:javascript
运行
复制
<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>

CustomerController

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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;
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-14 01:25:08

我解决了:右键单击JavaSe properties- CustomerManager Build Path - Librarires - JRE System LibrrariesJavaSe-13-编辑-将JavaSe-13更改为JavaSe-9 -finish -apply。

项目正在运行。但是为什么不使用JavaSe 13呢?

票数 0
EN

Stack Overflow用户

发布于 2020-06-12 18:24:59

快速解决方案:如果您从集成开发环境(eclipse或intellij)运行,打开文件/.settings文件。查看标记的值:<property name="context-root" value=获取该值,该值是URL的根元素。例如:如果它是"abc",那么你可以使用http://localhost:8082/abc/,如果值是其他值,则使用该值。

另一种选择是检查tomcat服务器下的server.xml下的值,并查看标记<Context docBase="abc" path="/abc"、take value of path和use in your URL。例如:http://localhost:8082/abc/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62334307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档