Spring MVC-404-原始服务器未找到当前表示形式

时间:2019-06-12 09:51:53

标签: spring spring-mvc tomcat9

我正在尝试部署Spring MVC Web应用程序。 我想将index.jsp重定向到另一个.jsp,但出现此错误。

HTTP Status 404 – Not Found

--------------------------------------------------------------------------------

Type Status Report

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

我的项目结构:

  • src / main / java
    • com.example.beans
    • com.example.controller
    • com.example.dao
  • src / main / webapp /
    • WEB-INF
    • / jsp
      • test.jsp
    • spring-servlet.xml
    • web.xml
    • index.jsp

spring-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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- Provide support for component scanning -->
    <context:component-scan
        base-package="com.example />

    <!--Provide support for conversion, formatting and validation -->
    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**"
        location="/resources/" />

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

    <bean id="ds"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver"></property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/dbexample></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>

    <bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="ds"></property>
    </bean>

    <bean id="dao" class="com.example.dao.ObjectDao">
        <property name="template" ref="jt"></property>
    </bean>

</beans>

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>Example</display-name>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

控制器

@Controller
public class MainController {

    @RequestMapping("hello")
    public String redirect() {
        return "viewpage";
    }

    @RequestMapping("/")
    public String display() {
        return "index";
    }

    @RequestMapping("test")
    public String test() {
        return "test";
    }

index.jsp

<html>
<body>
<h2>Hello World!</h2>


<a href="test">View test</a>  
<a href="hello">Click here...</a>  

</body>
</html>

当我点击测试时,我在sts日志中得到了这个错误:

  

org.springframework.web.servlet.DispatcherServlet noHandlerFound   警告:GET / example / hello

没有映射

1 个答案:

答案 0 :(得分:0)

您应该使用'/'映射控制器。

您可以尝试以下方法:

import tf.keras
model = tf.keras.Model(blah blah)
model.save('my_model.h5')

最好使用链接的相对路径:

@RequestMapping("/example/hello")
    public String redirect() {
        return "viewpage";
    }

有关pageContext see this

的更多信息