【问题标题】:Spring web application.Unable to view the view pageSpring Web 应用程序。无法查看视图页面
【发布时间】:2021-03-29 18:14:57
【问题描述】:

在我的控制台中出现以下错误

印刷机

2020 年 12 月 19 日下午 2:19:52 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:GET /FirstSpringWebExample/WEB-INF/hello.html 没有映射

我的文件如下, 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>FirstSpringWebExample</display-name>
 <servlet>
  <servlet-name>HelloWeb</servlet-name>
  <servlet-class>
     org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>

   <servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>/*</url-pattern>
   </servlet-mapping>
    </web-app>

HelloWeb-servlet.xml

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

<context:component-scan base-package = "com.sri.controller" />

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

 </beans>

HelloController.java

package com.sri.controller;

 import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;

 @Controller
 public class HelloController {
  @RequestMapping(value = "/hello", method = RequestMethod.GET)
   public String printHello(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");
      System.out.println("printing");
      return "hello";
   }
  @RequestMapping(value = "/hellot", method = RequestMethod.GET)
   public String printHellos(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");
      System.out.println("printing ra");
      return "hello";
   }
   }

你好.html

<html>
<head>
  <title>Hello Spring MVC</title>
</head>

<body>
  <h2>${message}</h2>
 </body>
 </html>

在上面的代码中。控制器工作正常,但视图不工作。这里正在获取请求的资源不可用。

【问题讨论】:

标签: java spring-mvc


【解决方案1】:

我已将html扩展更改为jsp扩展。现在它正在工作(不知道为什么InternalViewResolver无法呈现html页面)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多